Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with includes and mySQL query; I think? 1

Status
Not open for further replies.

iteach2

Technical User
Sep 16, 2001
120
US
Hi Gurus,

I have have a page in which I attached (3) includes. The first include generates links from a sql query and generates a menu, the second include generates a table filled with data from an sql query. The third include generates detailed info about the user that is logged in via an sql query.

The menu include somehow it is preventing the sql in the third include from running. When I comment out the sql in the menu include the third(table) include starts working again.

Is there a way php includes with sql queries can cancel one another out. If so how do you correct/prevent that.


Here is my code:


(this page has the sql that conflicts with the next set of code)

Index.php:

<?php



include 'library/config.php';

include 'library/opendb.php';



$sql = "SELECT *

FROM binary_data WHERE cid =" .$_SESSION['cid']."";


$result = mysql_query($sql) or die('Query failed. ' . mysql_error());

$num = mysql_numrows($result);

while($i < $num)
{

$link1=mysql_result($result,0,"id");
$link2=mysql_result($result,1,"id");
$link3=mysql_result($result,2,"id");
$link4=mysql_result($result,3,"id");

$i++;
}
include 'library/closedb.php';

?>



--------------------------------------------------------

properties.php

(none of the sql query comes back; nothing happens on this page unless comment out the sql on the code in the page above)

<?php ob_start(); session_start(); ?>
<?php


include 'library/config.php';

include 'library/opendb.php';



echo "<table border=0><font face=arial>";


echo "<tr><td bgcolor=khaki>";

echo "<b><font face=arial>Image</b>" . "</td><td bgcolor=khaki>";

echo "<b><font face=arial>Type</b></td>";

echo "<td bgcolor=khaki><b><font face=arial>Address</b>";

echo "</td><td bgcolor=khaki>";

echo "<b><font face=arial>Bedrooms</b>" . "</td><td bgcolor=khaki>";

echo "<b><font face=arial>Bathrooms</b>" . "</td><td bgcolor=khaki>";

echo "<b><font face=arial>Garage</b>" . "</td><td bgcolor=khaki>";

echo "<b><font face=arial>Square Feet</b>" . "</td><td bgcolor=khaki>";

echo "<b><font face=arial>List Date</b>" . "</td>";

echo "</tr>";





$query = "SELECT *

FROM properties

WHERE lcid = " .$_SESSION['cid']."";








$result = mysql_query($query) or die('Query failed. ' . mysql_error());

$num2=mysql_numrows($result);



while($i < $num2)

{

$media=mysql_result($result,$i,"media");

$type=mysql_result($result,$i,"type");

$address=mysql_result($result,$i,"address");

$city=mysql_result($result,$i,"city");

$state=mysql_result($result,$i,"state");

$zip=mysql_result($result,$i,"zip");

$bed=mysql_result($result,$i,"bed");

$bath=mysql_result($result,$i,"bath");

$garage=mysql_result($result,$i,"garage");

$sqfeet=mysql_result($result,$i,"sqfeet");

$listdate=mysql_result($result,$i,"listdate");



echo "<tr><td align=center><font face=arial>";

echo "<img src=\"$media\" width=120 height=90></img>" . "</td><td align=center><font face=arial>";

echo "$type" . "</td><td align=center><font face=arial>";

echo "$address<br>$city".","."$state"." $zip" . "</td><td align=center><font face=arial>";

echo "$bed" . "</td><td align=center><font face=arial>";

echo "$bath" . "</td><td align=center><font face=arial>";

echo "$garage" . "</td><td align=center><font face=arial>";

echo "$sqfeet" . "</td><td align=center><font face=arial>";

echo "$listdate" . "</td>";



$i++;

 
Are you getting any error messages when you run the script?

I noticed that in the Index.php file you have:
Code:
$num = mysql_numrows($result);
You are missing the underscore between num and rows:
Code:
$num = mysql_num_rows($result);
But if this was your problem, you should get a fatal error: 'undefined function'.
 
Hi,

Actually, I do not get any errors. The code runs but it does not show the database generated code.
 
I still do not see anything in the code that would cause what you describe. Lacking any other thoughts...

In your php.ini file, is display_errors set to true (1)? If not, or if you don't feel like checking :) place this code at the top of the file which includes the files you posted above and see if you get any errors.
Code:
ini_set('display_errors', 1);

HTH
 
Thanks for your help. It got me thinking in the right direction...turns out that the code blocks were cancelling each other out. Both pages have a while loop that uses the variable $i

Code:
while($i < $num)
	{  
[\code] 

So on the conflicting page I changed the $i to $z and all began working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top