me1000 Posted June 1, 2006 Share Posted June 1, 2006 ok i have a bit of a problem...im using the following code to query the database, first it searchs for the cat, and then it will see if the can is aproved. 1 being yes, 0 being no.[code]<?$inCatID = (is_numeric($_REQUEST['cat'])) ? $_REQUEST['cat'] : 1; $query = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1";?>[/code]please tell me if that code is messed up at all! its grabbing the ID, TUT_TITLE, and AUTHOR fields from the database table.______________________________________________________________________now im using a while loop to display teh results. this is messy!!![code]<table width="100%" border="0"> <tr> <td width="50%"><font size="2">Tutorial Title </font></td> <td width="50%"><font size="2">Tutorial Author </font></td> </tr> <tr> <td> </td> <td> </td> </tr> <? // get count of rows returned by queryif (mysql_num_rows($query) > 0) { while($r=mysql_fetch_array($query)){ $tut_title = $_CONTENT['TUT_TITLE']; $tut_author = $_CONTENT['AUTHOR']; $tut_id = $_CONTENT['ID']; $link = '<a href ="view_tuts.php?id='.$tut_id.'">'.$tut_title.'</a>'; $author_link = '<a href ="userinfo.php?user='.$tut_author.'">'.$tut_author.'</a>'; echo "<tr><td width=50%><font size='2'>". $link."</font></td><td width=50%><font size='2'>". $author_link."</font></td></tr>";} }else { echo "<tr> <td colspan='2'> No tutorials Found! </td> </tr>";} ?></table>[/code]I have an entry in the database that matches what the query is looking for but im getting No Tutorials Found!Please help!-Thanks Link to comment https://forums.phpfreaks.com/topic/10917-solved-querying-database/ Share on other sites More sharing options...
Barand Posted June 1, 2006 Share Posted June 1, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$query = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1";[/quote]That defines the query but you have to execute it.Try[code]$querySQL = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1";$query = mysql_query($querySQL) or die (mysql_error() . '<br> in : <br>'' . $querySQL);[/code]If it is messed up, you will get the error message telling you why and the query string will be echoed' Link to comment https://forums.phpfreaks.com/topic/10917-solved-querying-database/#findComment-40809 Share on other sites More sharing options...
me1000 Posted June 1, 2006 Author Share Posted June 1, 2006 ok, Thanks for that. now I want them in ASC order.so that the last row of the database displays first.[code]$querySQL = "SELECT ID, TUT_TITLE, AUTHOR FROM $sTableName WHERE TUT_CAT=$inCatID AND APROVED = 1 ORDER BY ID ASC";[/code]all i did was modify the $querySQL line to look like so. but for some reason that didnt make a diffrence at all! Link to comment https://forums.phpfreaks.com/topic/10917-solved-querying-database/#findComment-40925 Share on other sites More sharing options...
me1000 Posted June 1, 2006 Author Share Posted June 1, 2006 Nevermind I figured everything out!Thanks for all your help! :) Link to comment https://forums.phpfreaks.com/topic/10917-solved-querying-database/#findComment-40961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.