ayok Posted July 31, 2007 Share Posted July 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/ Share on other sites More sharing options...
ayok Posted July 31, 2007 Author Share Posted July 31, 2007 Could anybody give me a clue? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-311745 Share on other sites More sharing options...
hostfreak Posted July 31, 2007 Share Posted July 31, 2007 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-311751 Share on other sites More sharing options...
ayok Posted July 31, 2007 Author Share Posted July 31, 2007 Hey, it works! I'm not sure where I've got the code from, but it suppose to tell me what's the error.. :-\ Thank you.. this site is super! cheers, ayok Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-311761 Share on other sites More sharing options...
ayok Posted July 31, 2007 Author Share Posted July 31, 2007 What's wrong with include "something.php"? sometimes it works, sometimes i got this error. I use it mostly to include the database connection. However, I often got this error: failed to open stream: No such file or directory . Do I need to use different code? Thanks, ayok Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312262 Share on other sites More sharing options...
hostfreak Posted July 31, 2007 Share Posted July 31, 2007 Check out: http://php.net/include & http://www.php.net/manual/en/ini.core.php#ini.include-path The only thing that comes to mind would be your include path. Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312265 Share on other sites More sharing options...
dbillings Posted July 31, 2007 Share Posted July 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312271 Share on other sites More sharing options...
hostfreak Posted July 31, 2007 Share Posted July 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312278 Share on other sites More sharing options...
ayok Posted July 31, 2007 Author Share Posted July 31, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312288 Share on other sites More sharing options...
almightyegg Posted July 31, 2007 Share Posted July 31, 2007 force an error? include 'non_existent_file.php'; that might do it, Copy and paste the url it gives EDIT: No http:// either Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312293 Share on other sites More sharing options...
ayok Posted July 31, 2007 Author Share Posted July 31, 2007 Hi! I'm sorry! my mistake.. worng folder.. Thank you guys, you're awesome! regards, ayok Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312302 Share on other sites More sharing options...
dbillings Posted July 31, 2007 Share Posted July 31, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/62627-just-blank/#findComment-312329 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.