Jump to content

MySQL in PHP not printing results


Go to solution Solved by remenissions,

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/276453-mysql-in-php-not-printing-results/
Share on other sites

  • Solution

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

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.