rj300 Posted April 3, 2013 Share Posted April 3, 2013 Hi guys I'm trying to print the results from a query but it keeps printing "No Result" but it should print one query result. Can someone please help? My code is as follows <form action= "search.php" method="post"> <tr> <td>Location:</td><td> <input type="text" name="loc" maxlength="20"/> </td> </tr> <tr> <td>Date:</td><td> <input type="text" name="date" maxlength="20"/></td> </tr> <tr> <td>Category: </td><td><input type="text" name="category" maxlength="20"/></td> </tr> <tr> <td><input type="submit" value="Submit"/></td> </tr> </form> <?php $username="root"; $password=""; $database='calendar'; $get_location=mysql_real_escape_string($_POST['loc']); $get_doe=mysql_real_escape_string($_POST['date']); $get_category=mysql_real_escape_string($_POST['category']); mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query=mysql_query("SELECT f.EVENT, f.LOCATION, f.DOE, f.CATEGORY, f.PRICE, (( ( f.NUMOFLOC * ( Log(f.LOGLOC) ) ) + ( f.NUMOFDOE * ( Log(f.LOGDOE) ) )+ (f.NUMOFCAT * (Log(f.LOGCAT))))) AS FINALRANK FROM (SELECT E.EVENT,ED.LOCATION, ED.DOE,ED.CATEGORY,ED.PRICE, ((ROUND( ED.NUMOFSET / ED.NUMOFLOC ))) AS LOGLOC, ((ROUND( ED.NUMOFSET / ED.NUMOFDOE ))) AS LOGDOE, ((ROUND( ED.NUMOFSET / ED.NUMOFCAT ))) AS LOGCAT, ED.NUMOFLOC, ED.NUMOFDOE, ED.NUMOFCAT FROM EVENT E, EVENTDETAIL ED WHERE E.EVENTID = ED.EVENTID AND ED.LOCATION LIKE '".$get_location."' AND ED.CATEGORY LIKE '".$get_category."' AND ED.DOE LIKE '".$get_doe."') f ORDER BY FINALRANK DESC;"); $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; if(!$num){ echo ("No Results"); } else{ echo '<table border ="0" width ="30" height="20">'; echo '<tr><th colspan ="7" align="middle"> Results</th> </tr>'; echo'<td>Rank</td> <td>Event</td> <td>Loc</td> <td>Date</td> <td>Price</td>'; while ($i < $num) { $eventid=mysql_result($result,$i,"EVENT"); $location=mysql_result($result,$i,"LOCATION"); $doe= mysql_result($result,$i,"DOE"); $price= mysql_result($result,$i,"PRICE"); echo '<tr>'; echo "<td> ".($i+1)."</td><td>$eventid</td><td>$location</td><td>$doe</td><td> $price </td>"; echo "<br>"; echo'</tr>'; echo"<br>"; $i++; } } ?> I think there is some problem when i inject the parameters into the query '$get_location' etc as it it not recognising it and going stright to the if(!$num) statement. Please help Quote Link to comment https://forums.phpfreaks.com/topic/276453-mysql-in-php-not-printing-results/ Share on other sites More sharing options...
Solution remenissions Posted April 3, 2013 Solution Share Posted April 3, 2013 Well I noticed for one $query = mysql_query(""); $result = mysql_query($query); Should be $query = ""; If that doesn't solve it then ontop of that try using while($row = mysql_fetch_array($result)) { echo "<br>".$row['EVENT']."<br>".$row['DOE'];// so on so forth } Quote Link to comment https://forums.phpfreaks.com/topic/276453-mysql-in-php-not-printing-results/#findComment-1422574 Share on other sites More sharing options...
rj300 Posted April 3, 2013 Author Share Posted April 3, 2013 Thanks, that worked!!! Quote Link to comment https://forums.phpfreaks.com/topic/276453-mysql-in-php-not-printing-results/#findComment-1422630 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.