• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help with my array please?

TruePaige

Diamond Member
Hey guys, I was creating an array in PHP through pulling values from two tables where the id matches and sadly I get an error.

$result = mysql_query("SELECT s1.pfiles
FROM pfiles s1, puploads s2
where s1.id = s2.id and
s2.tags = $search");

$row = mysql_fetch_array($result);
$tagdata = $row;

print_r($tagdata);


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in W:\www\fs\layout\test\tpl_tagcloud.php on line 128


If any of you could help I'd appreciate it. =)
 
Originally posted by: trexpesto
curious - can you print $result ?

It doesn't throw an error, but it doesn't display anything.

In case your curious, I am connected properly

$search=$_GET['search'];
htmlspecialchars(stripslashes($search));
mysql_connect('lREMOVED', 'REMOVED', 'REMOVED');
mysql_select_db('fileupload');
 
Originally posted by: troytime
it means your query is returning 0

if(!mysql_num_rows($result))
echo "no rows returned";

Huh..I wonder why that's happening...any things that would cause that? I reference these rows throughout the program and it works...hmm
 
try wrapping your query around ' and concatenate the PHP variable

Code:
$query = "SELET * FROM this WHERE something='".$search."';"; //i ended the query string in ";" and also ended the PHP statement with ";"

If search is from user input, make sure it's escaped properly!

also, I would set it up like this for better error handing:



edit: attach code sucks!

$query = "SELECT s1.pfiles
FROM pfiles s1, puploads s2
where s1.id = s2.id and
s2.tags='".$search."';";
$result_set = mysql_query($query) or die('error: '+mysql_error());
if(mysql_num_rows > 0) {
while($row = mysql_fetch_array($result_set) {
//do something per row - assuming multiple rows returned
} else {
echo 'No Rows Returned';
}
}
 
Back
Top