what is wrong here blank output

hi all merry xmass

just wondering whats wrong here im gettin no error or no out put just the html in the echo tag

[php]<?php
include (“includes/db_config.php”);

mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database) or die( “Unable to select database”);
$query=“SELECT * FROM shaun WHERE id =’”.$id."’";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo “test

the main thumbnail page

”; /// get this output

$i=0; ///iv tryed this as 1 onstead of 0 but still no output
while ($i < $num) {

$id=mysql_result($result,$i,“id”);
$pro_name=mysql_result($result,$i,“pro_name”);
$thumbnail=mysql_result($result,$i,“thumbnail”);
$short_details=mysql_result($result,$i,“short_details”);
$full_details=mysql_result($result,$i,“full_details”);
$link=mysql_result($result,$i,“link”);
$image1=mysql_result($result,$i,“image1”);
$image2=mysql_result($result,$i,“image2”);
$image3=mysql_result($result,$i,“image3”);
$image4=mysql_result($result,$i,“image4”);

echo " $link $image1 $pro_name "; //but not this out put

$i++;
}

?>
[/php]

FYI the page im working on is @ http://nbbcj.co.uk/project/detalis.php?id=1
thanks for any help :slight_smile:
nbbcj

[php]$num=mysql_numrows($result);[/php]

Should be:

[php]$num=mysql_num_rows($result);[/php]

Do you have PHP errors turned on? It might be that an error has occurred and it’s not being displayed. You can always put:

[php]error_reporting(E_ALL);[/php]

While you’re developing it.

hi there jsherz
thank you for your reply and the advice about the
[php]error_reporting(E_ALL);[/php] really useful as i found out the prob was

Notice: Undefined variable: id in /customers/0/8/d/nbbcj.co.uk/httpd.www/project/detalis.php on line 7 

as i didnt use the get tag as im getting the variable from the url so have to use
[php]$query=“SELECT * FROM shaun WHERE id =’”.$_GET[‘id’]."’";[/php]

thank you for your help again :slight_smile:
nbbcj

Unless db_config.php is creating the variable $id, you will need to put on a line somewhere above the use of it (maybe under the include) the following line:

[php]$id = isset($_GET[‘id’]) ? trim($_GET[‘id’]) : ‘’;[/php]

(If the id has been set, $id will use that value - if not, it will be an empty string.)

the db_config holds the val’s for $db_hostname $db_username $db_password $db_database
i was thinking the GET part is used cuz it is pass in the url eg page.php?id=1 and the one come from the index page that gets the value from the DB
[php]$id=mysql_result($result,$i,“id”);[/php]
and the link looks like this

[php]<a href=“detalis.php?id=$id”>[/php]

am i on the right line here as i say im new to php and sql :slight_smile:

thank you for you help so much can i ask you one more question
How to display mysql results horizontal so my thum images go left to right with there corresponding names under there images ???

my working code for the page in question
[php]<?php
include (“includes/db_config.php”);

mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database) or die( “Unable to select database”);
$query=“SELECT * FROM shaun”;
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo “main index

the main thumbnail page

”;

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,“id”);
$pro_name=mysql_result($result,$i,“pro_name”);
$thumbnail=mysql_result($result,$i,“thumbnail”);
$short_details=mysql_result($result,$i,“short_details”);
$link=mysql_result($result,$i,“link”);

echo "

“;
echo " “;
echo " “;
echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo " "; echo "
<a href=“detalis.php?id=$id”><img src=”/project/thum/$thumbnail” alt=”$thumbnail" height=“150” width=“150” />
$pro_name
$short_details
";

$i++;
}

?>

[/php]

<?php include ("includes/db_config.php"); mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database) or die( "Unable to select database"); $query="SELECT * FROM shaun"; $result=mysql_query($query); while($mfa=mysql_fetch_array($result)) { echo "";//for fetching all images from table } ?>
"; echo "

hay all thanks for your help with a bit of google in i worked out how to sort it all and even added some filtering :slight_smile:

here is my new working code

[php]


Filters

•home
•Filter1
•Filter2
•Filter3

<?php error_reporting(E_ALL);

include (“includes/db_config.php”);

mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database) or die( “Unable to select database”);

if(isset($_GET[‘cat’]) && !empty($_GET[‘cat’])){
$escape_cat = mysql_real_escape_string($_GET[‘cat’]);
$query=“SELECT * FROM shaun WHERE cat =’”.$escape_cat."’";
}else{
$query="SELECT * FROM shaun";
}

$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error());
if($result && mysql_num_rows($result) > 0)
{
$i = 0;
$max_columns = 3;
while($row = mysql_fetch_array($result))
{
// make the variables easy to deal with
extract($row);

   // open row if counter is zero
   if($i == 0)
      echo "<tr>";

   // make sure we have a valid product
   if($pro_name != "" && $pro_name != null)
      echo "<td><a href=\"detalis.php?id=$id\"><img src=\"/project/thum/$thumbnail\" alt=\"$thumbnail\" height=\"150\" width=\"150\" /><br>$pro_name<br></a>$short_details $cat</td>";

   // increment counter - if counter = max columns, reset counter and close row
   if(++$i == $max_columns) 
   {
       echo "</tr>";
       $i=0;
   }  // end if 

} // end while
} // end if results

// clean up table - makes your code valid!
if($i > 0){ for($j=$i; $j<$max_columns;$j++) echo "

"; echo ‘’;} ?>
 
[/php]

Filters

•home
•Filter1
•Filter2
•Filter3

<?php error_reporting(E_ALL);

include (“includes/db_config.php”);

mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database) or die( “Unable to select database”);

if(isset($_GET[‘cat’]) && !empty($_GET[‘cat’])){
$escape_cat = mysql_real_escape_string($_GET[‘cat’]);
$query=“SELECT * FROM shaun WHERE cat =’”.$escape_cat."’";
}else{
$query="SELECT * FROM shaun";
}

$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error());
if($result && mysql_num_rows($result) > 0)
{
$i = 0;
$max_columns = 3;
while($row = mysql_fetch_array($result))
{
// make the variables easy to deal with
extract($row);

   // open row if counter is zero
   if($i == 0)
      echo "<tr>";

   // make sure we have a valid product
   if($pro_name != "" && $pro_name != null)
      echo "<td><a href=\"detalis.php?id=$row[id]\"><img src=\"/project/thum/$row[thumbnail]\" alt=\"$row[thumbnail]\" height=\"150\" width=\"150\" /><br>$row[pro_name]<br></a>$row[short_details] $cat</td>";

   // increment counter - if counter = max columns, reset counter and close row
   if(++$i == $max_columns) 
   {
       echo "</tr>";
       $i=0;
   }  // end if 

} // end while
} // end if results

// clean up table - makes your code valid!
if($i > 0){ for($j=$i; $j<$max_columns;$j++) echo "

"; echo ‘’;} ?>
 

if you using

while($row=mysql_fetch _array($query))
{
echo $row[‘column name of the table’];// This is the right way to fetching data from the table
}

If any other you have query than feel free to ask.

Sponsor our Newsletter | Privacy Policy | Terms of Service