Jump to content

Recommended Posts

Hi,

Please let me tell you my problem with my php script.

 

I want to show a table in a webpage.

Here is the script for db connection:

<?
$db_link = mysql_connect("localhost", "root", "");
if (!$db_link) {
   die("Could not connect: " . mysql_error());
}
mysql_select_db("shopping") or die("Could not select database");
?>

 

And this is my product list php:

<?php
echo "<H3 align=center>Product List</H3>";
include "dbconnect.php";
$tampil=mysql_query("SELECT * FROM products ORDER BY PkProduct DESC");
if($total=@mysql_num_rows($tampil)){
return $total;
} else {
print (mysql_error());
}
$url="http://localhost/newstore/products";

echo "<table align=center border=1><tr>
<th>Categories</th>
<th>Product names</th>
<th>Contents</th>
<th>Prices</th>
<th>Images</th></tr>";

while ($data=@mysql_fetch_array($tampil))
{
echo"<td>$data[FkFamily]</td>";
echo"<td>$data[Name]</td>";
echo"<td>$data[Content]</td>";
echo"<td>$data[Price]</td>";
echo"<td><img src='$url/$data[image]'</td></tr>";
}
?>

 

When I open my browser, I only see the title "Product List" and no table, nor error message.

 

What's wrong with my script? How can I see the mistakes?

 

Thank you,

ayok

Link to comment
https://forums.phpfreaks.com/topic/62627-just-blank/
Share on other sites

Try:

 

<H3 align=center>Product List</H3>
<?php
include "dbconnect.php";
$tampil = mysql_query("SELECT * FROM products ORDER BY PkProduct DESC") or DIE(mysql_error());
$url = "http://localhost/newstore/products";
?>

<table align=center border=1>
    <tr>
        <th>Categories</th>
        <th>Product names</th>
        <th>Contents</th>
        <th>Prices</th>
        <th>Images</th>
    </tr>

<?php
while (($data = mysql_fetch_array($tampil)) && (mysql_num_rows($tampil) > 0))
{
    echo "<tr>";
    echo "<td>$data['FkFamily']</td>";
    echo "<td>$data['Name']</td>";
    echo "<td>$data['Content']</td>";
    echo "<td>$data['Price']</td>";
    echo "<td><img src='$url/$data['Image']'</td>";
    echo "</tr>
}
?>

</table>

 

I wasn't really sure the point of this portion of your script:

if($total=@mysql_num_rows($tampil)){
return $total;
} else {
print (mysql_error());
}

Link to comment
https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-311751
Share on other sites

something.php needs to be in the same directory as the page you are calling it from.

 

if not then it will give you that error

 

No it doesn't.

 

Page 1:

include("directory/something.php");

 

directory>something.php

blah blah ...

 

Will include and work. He would just need to modify his include path.

Link to comment
https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312278
Share on other sites

Hey thanks,

I put all in the same directory.

My code: include "dbconnect.php"; and dbconnect.php is in the same folder. I have other pages which use include "dbconnect.php" and it works fine (like the codes from hostfreak above). I don't know why this time I've got no database is selected.

 

I already tried include ("dbconnect.php"), but still doesn't work. How can I get the right path?

I'm working in localhost. how can I define the path? .:C:\apache\htdocs... or http://localhost/directory/...?

 

Thank you,

ayok

Link to comment
https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312288
Share on other sites

something.php needs to be in the same directory as the page you are calling it from.

 

if not then it will give you that error

 

No it doesn't.

 

Page 1:

include("directory/something.php");

 

Thats not how he had it setup now is it. He had ...

 

include("something.php");

 

With that format if "something" isn't in the same directory it's not going to work.

Link to comment
https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312329
Share on other sites

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.