m00nz00mer Posted February 19, 2008 Share Posted February 19, 2008 hey im having some problems with this join... $reviewedByQuery = "SELECT nbc_user.userName FROM nbc_user INNER JOIN nbc_bookreview ON nbc_user.userID = nbc_bookreview.userID WHERE nbc_bookreview.bookISBN = '".$_GET['bookID']."'"; $reviewedByQueryResult = mysql_query($reviewedByQuery) or die("Query error: ".mysql_error()); $reviewedBy = mysql_result($reviewedByQueryResult, 0); and im getting this error: Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 10 in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_p185724/public_html/bookinfo.php on line 198 Reviewed by: anyone know why im getting this error? cheers. Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/ Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Check to see if rows were returned before using mysql_result. Sounds like no rows were returned so Row 0 doesn't exist. Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470956 Share on other sites More sharing options...
m00nz00mer Posted February 19, 2008 Author Share Posted February 19, 2008 is there a quick way to do that? Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470965 Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 $reviewedByQueryResult = mysql_query($reviewedByQuery) or die("Query error: ".mysql_error()); if (mysql_num_rows($reviewedByQueryResult )) > 0 { $reviewedBy = mysql_result($reviewedByQueryResult, 0); } else { echo "No rows found"; } Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470967 Share on other sites More sharing options...
craygo Posted February 19, 2008 Share Posted February 19, 2008 $reviewedByQueryResult = mysql_query($reviewedByQuery) or die("Query error: ".mysql_error()); $num_rows = mysql_num_rows($reviewedByQueryResult); if($num_rows > 0){ $reviewedBy = mysql_result($reviewedByQueryResult, 0); } else { echo "No rows returned"; } Damn got beat again Ray Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470968 Share on other sites More sharing options...
m00nz00mer Posted February 19, 2008 Author Share Posted February 19, 2008 ah yes it works!!! just didnt return anything... how can i make it so if there are no returns it displays a message??? Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470969 Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Both of our examples have an Else that will display if No Rows were found. ah yes it works!!! just didnt return anything... how can i make it so if there are no returns it displays a message??? Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470971 Share on other sites More sharing options...
m00nz00mer Posted February 19, 2008 Author Share Posted February 19, 2008 Ok i see what u mean but when i try the following it works when there is data in row0 but when there is no data, i still get an error? $reviewedByQuery = "SELECT nbc_user.userName FROM nbc_user INNER JOIN nbc_bookreview ON nbc_user.userID = nbc_bookreview.userID WHERE nbc_bookreview.bookISBN = '".$_GET['bookID']."'"; $reviewedByQueryResult = mysql_query($reviewedByQuery); $reviewedBy = mysql_result($reviewedByQueryResult, 0); $reviewedByQueryResult = mysql_query($reviewedByQuery) or die("Query error: ".mysql_error()); $num_rows = mysql_num_rows($reviewedByQueryResult); if($num_rows > 0){ //Display Review Query echo "Reviewed by: <div class='detailTextGrey'>".$reviewedBy."</div>"; } else { echo "No rows returned"; } Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470975 Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Both our examples show your mysql_result inside the IF statement, you are taking it out. Use the code we gave you above and modify. Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470983 Share on other sites More sharing options...
m00nz00mer Posted February 19, 2008 Author Share Posted February 19, 2008 ok i have tried this ... but im not not retreving the correct info... im im now getting Resource id #10 instead of a value.. this is the code now... $reviewedByQueryResult = mysql_query($reviewedByQuery) or die("Query error: ".mysql_error()); $num_rows = mysql_num_rows($reviewedByQueryResult); if($num_rows > 0){ //Display Review Query echo "Reviewed by: <div class='detailTextGrey'>".$reviewedByQueryResult."</div>"; } else { echo "No rows returned"; } Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470988 Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 Now you left out your mysql_result Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470990 Share on other sites More sharing options...
m00nz00mer Posted February 19, 2008 Author Share Posted February 19, 2008 ok so i tried this... $reviewedByQueryResult = mysql_query($reviewedByQuery); $reviewedBy = mysql_result($reviewedByQueryResult, 0); $num_rows = mysql_num_rows($reviewedByQueryResult); if($num_rows > 0){ //Display Review Query echo "Reviewed by: <div class='detailTextGrey'>".$reviewedBy."</div>"; } else { echo "No rows returned"; } and it returns the value but it still gives an error when northing is returned? Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470993 Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 $reviewedByQueryResult = mysql_query($reviewedByQuery); $num_rows = mysql_num_rows($reviewedByQueryResult); if($num_rows > 0){ $reviewedBy = mysql_result($reviewedByQueryResult, 0); // HERE //Display Review Query echo "Reviewed by: <div class='detailTextGrey'>".$reviewedBy."</div>"; } else { echo "No rows returned"; } Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-470996 Share on other sites More sharing options...
m00nz00mer Posted February 19, 2008 Author Share Posted February 19, 2008 thank you, thought i was being stupid! Link to comment https://forums.phpfreaks.com/topic/91959-problem-with-joins/#findComment-471004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.