Hello,

I am trying to show a list of information using a FETCH and WHERE statements.

This is my code:

$buds = mysql_query("SELECT * FROM buds2 WHERE bud_me = '$userid' AND confirmed= '1'");

$x = 1;
while ($array = mysql_fetch_array($buds))
{
	$buddy = fetch("SELECT display_name,username FROM members2 WHERE id = '$array[bud_you]' AND game = '$game'");
	
	$buddy2 = fetch("SELECT photo_selected,location,my_update FROM members_profiles2 WHERE username = '$buddy[username]' AND game = '$game'");




	if (!$array[bud_note]) { $array[bud_note] = "<i>No notes on this buddy.</i>"; }

	$mybuds .= "
	<TABLE CELLSPACING=5 CELLPADDING=0 WIDTH=95% BGCOLOR=\"$reallyLight\">
		<TR>
			<TD VALIGN=top><center>
			 <P><a target=_blank href=user_profile.php?user=$buddy[username]&game=$game><FONT SIZE=\"+1\"
color=#000000><b>$buddy[display_name]</b></FONT></a><p>
			 <BR><img src='photos/$buddy2[photo_selected]' width=80 ><FONT SIZE=\"-1\"><I>
			 <a href=buds_edit.php?game=$game&bud=$array[bud_you]>Edit</a>,
		     <a href=delete_bud.pro.php?game=$game&bud=$array[bud_you]><font
color=red>Remove</font></a></I></FONT>
			 </P>
			 <P><font size=-1><B>Notes:</B> $array[bud_note]</font></P>
			</TD>
		</TR>
	</TABLE><br>";
}

I can get this code to work normally WITHOUT using the WHERE confirmed='1' code but whenever I try to use this it just doesnt show anything from the table!

Please Help

Many Thanks

Dani AI

Generated

A few focused checks will quickly reveal why adding the confirmed clause returns no rows. The usual causes are: the column does not actually contain the literal value being tested (different text, trailing whitespace, non-printable bytes, or a different data type), the query string was accidentally mangled when built, or an earlier routine (the custom fetch() or a variable like $userid) is hiding the real problem. is right to flag quoted integers as a style/typing concern, and ’s note about an extra "confirmed" token strongly suggests the SQL string is being built or concatenated incorrectly.

Quick diagnostic steps to run on the server/CLI (these will show actual stored values and any hidden characters):

SELECT DISTINCT confirmed, HEX(confirmed), LENGTH(confirmed)
FROM buds2
WHERE bud_me = 123;

And in PHP, dump the query, the mysql error and the row count before fetching:

$sql = "..."; // the constructed SQL string
var_dump($sql);
$res = mysql_query($sql) or die('mysql_error: '.mysql_error());
var_dump(mysql_num_rows($res));
while ($r = mysql_fetch_assoc($res)) var_dump($r);

If the HEX/LENGTH output shows extra bytes, apply TRIM or update the table to use canonical values (0/1). If the confirmed column is tinyint, using confirmed = 1 (no quotes) is cleaner; if stored as text use the exact stored token. Confirm the schema and sample rows with a direct SELECT in phpMyAdmin or the MySQL client.

Also confirm what the custom fetch() does — it may hide errors or return false. For long-term robustness and security consider switching from deprecated mysql_* to PDO or mysqli with prepared statements (see PHP manual on mysql_error and mysql_num_rows and the PDO/mysqli sections).

Recommended Answers

All 2 Replies

Hmm dunno how but there is an extra confirmed in this line of code:

$buds = mysql_query("SELECT * FROM buds2 WHERE bud_me = '$userid' AND confirmed= '1'");

This is only ONE AND confirmed in the code!

I see all your ID's are quoted. If they are integers, they shouldn't be. Only strings and string-like data should be quoted.

I also can not find any reference to the fetch() function you are using. Is this something you made, or from some 3'rd party include?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.