Forum Moderators: coopster

Message Too Old, No Replies

MySQL Select Not Working

little help?

         

adammc

9:38 am on Mar 9, 2007 (gmt 0)

10+ Year Member



Hi guys,

I am really stumped and need a fresh set of eyes!
Can anyone help?

[php]
// make the query to get the members info
$query5 = "select profile_id, profile_complete, validated from matrimonial WHERE username='$_SESSION[username]'";
$result5 = @mysql_query ($query5);

while($row5=mysql_fetch_array($result5))
{

if ($row5['validated'] == '1') {

echo '<li><a href="matrimonial-view.php?profile=' . $row5['profile_id'] . '" class="gen">View your profile</a><br />';

} else {

echo '<li><a href="my-profile.php" class="gen">Add your profile</a><br />';

}
}
[/php]

This code should be echoing 'view your profile' or 'add your profile' depending on the result of the query, for some unknown reason it is echoing nothing?

omoutop

9:59 am on Mar 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Change $result5 = @mysql_query ($query5); to something like
$result5 = mysql_query ($query5) or die(mysql_error());

and see if there are any error in your query

cameraman

10:00 am on Mar 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your problem is here:
username='$_SESSION[username]'"

it should be:
username='{$_SESSION['username']}'"

If that doesn't end up fixing it, try removing the @ so you can see the error.

adammc

11:53 am on Mar 9, 2007 (gmt 0)

10+ Year Member



Thanks for the replies :)

I have worked out that if there are no results for the query, nothing is printed if there is 'View your profile' is printed.

So I am guessing that my if else or the if ($row5['validated'] == '1') { is constructed wrong.

If there are no results for th query I want it to print the other line.

omoutop

12:05 pm on Mar 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



then try this:

$num_results = mysql_num_rows($result5);
if ($num-results>0)
{
// execute code
}
else
{
echo "no results found";
}

joelgreen

3:46 pm on Mar 9, 2007 (gmt 0)

10+ Year Member



// make the query to get the members info
$query5 = "select profile_id, profile_complete, validated from matrimonial WHERE username='{$_SESSION[username]}'";
$result5 = @mysql_query ($query5);

if($row5=mysql_fetch_array($result5))
{

if ($row5['validated'] == '1') {

echo '<li><a href="matrimonial-view.php?profile=' . $row5['profile_id'] . '" class="gen">View your profile</a><br />';

} else {

echo '<li><a href="my-profile.php" class="gen">Add your profile</a><br />';

}

}
else {
the text to show if no info
}

if($row5=mysql_fetch_array($result5)) clause will return false if no rows and will execute else clause