tammic Posted November 23, 2009 Share Posted November 23, 2009 I am an absolute newby at PHP. This is my first project. Read the PHP/MySQL for Dummies book over and over. Can you tell me what I am missing? This is really driving me nuts. Code is as follows: <?php include("PenInfo.php"); $connection=mysql_connect($host,$user,$password) or die ("Couldn't Connect To Server"); $db=mysql_select_db($database,$connection) or die ("Couldn't Select Database"); $query="SELECT * FROM tblMaterials WHERE(((tblMaterials.StillAvail)='Yes')) ORDER BY tblMaterials.MatSortOrder"; $result=mysql_query($query) or die ("Couldn't Execute Query"); /* Display Results in a Table */ echo "<div id='samptable' align='center' style='width: 794'>"; echo "<table id='matsamp' summary='Examples of natural and dyed woods along with man-made materials used to create your custom hand made pen or pencil' style='border-collapse: collapse; font-family: Tahoma; font-size: 10pt; color: #800000' cellspacing='1'>"; echo "<tr> <td width='295' align='center'> <img alt='{$row['MatName']} Material Sample' src='images/MaterialSamples/{$row['MatPic']}' width='237' height='75'><br> {$row['MatName']}</td> <td width='295' align='center'> <img alt='{$row['MatName']} Material Sample' src='images/MaterialSamples/{$row['MatPic']}' width='237' height='75'><br> {$row['MatName']}</td> </tr>"; echo "</table>"; echo "</div>"; echo "<div id='footer'> <hr style='text-align:center; width:500px; height:1px; color:#800000;'> <p> </p> <p><a href='index.htm'>Home</a> | <a href='gallery.htm'>Gallery</a> | <a href='styles.htm'>Styles</a> | <a href='matsamp1.htm'>Samples</a> | <a href='order.htm'>Order</a> | <a href='contact.htm'>Contact</a> | <a href='about.htm'>About</a> | <a href='faq.htm'>FAQ</a></p> <p><br/>© 2005 Beauty Beneath The Bark All Rights Reserved | <a href='privacy.htm'>Privacy Statement</a> </p> <p> <img src='images/valid-html401.gif' alt='Valid HTML 4.01 Transitional' width='88' height='31'/> </p> </div>"; ?> What I get when I run this is the results at http://www.beautybeneaththebark.com/MaterialSamps.php What it should look very similar to is http://www.beautybeneaththebark.com/matsamp1.htm All assistance is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/182672-why-wont-this-work-need-a-little-help/ Share on other sites More sharing options...
iSE Posted November 23, 2009 Share Posted November 23, 2009 Where's the $row variable coming from? When doing any programming, your best writing out the comments first to get in your head in plain english the process you want to go to... So: Create connection If connection created perform query If query success get results Loop through results... I'll give you a hand here, use... <?php while (($row = mysql_fetch_row($result)) !== false) { } ?> Show material image etc... You may want to check that mysql_fetch_row is the right command you wish to use... A handy resource we all hammer every day we're programming is http://www.php.net. Also, I'd recommend that you use MySQLi as soon as you feel comfortable as the traditional MySQL extension is being phased out Hope this helps, iSE Quote Link to comment https://forums.phpfreaks.com/topic/182672-why-wont-this-work-need-a-little-help/#findComment-964117 Share on other sites More sharing options...
cags Posted November 23, 2009 Share Posted November 23, 2009 Assuming your query works correctly $result will contain a resource object. In order to access the information in this object you need to use one of the other mysql_ functions and you will also need to loop through the results. Judging by your code further down you want to be using mysql_fetch_assoc. Without being able to test it's difficult to say for sure, but your code should probably look more like this... echo "<div id='samptable' align='center' style='width: 794'>"; echo "<table id='matsamp' summary='Examples of natural and dyed woods along with man-made materials used to create your custom hand made pen or pencil' style='border-collapse: collapse; font-family: Tahoma; font-size: 10pt; color: #800000' cellspacing='1'>"; while($row = mysql_fetch_assoc($result)) { echo "<tr> <td width='295' align='center'> <img alt='{$row['MatName']} Material Sample' src='images/MaterialSamples/{$row['MatPic']}' width='237' height='75'><br> {$row['MatName']}</td> </tr>"; } echo "</table>"; echo "</div>"; echo "<div id='footer'> Bare in mind that will only produce 1 item per line, but if this works we'll go from there, I didn't want to take too big a step. Quote Link to comment https://forums.phpfreaks.com/topic/182672-why-wont-this-work-need-a-little-help/#findComment-964120 Share on other sites More sharing options...
tammic Posted November 23, 2009 Author Share Posted November 23, 2009 I really appreciate the help. This is all very new to me and your assistance in writing the correct code was very helpful. I will test this today and hopefully it all works. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/182672-why-wont-this-work-need-a-little-help/#findComment-964148 Share on other sites More sharing options...
tammic Posted November 23, 2009 Author Share Posted November 23, 2009 Bare in mind that will only produce 1 item per line, but if this works we'll go from there, I didn't want to take too big a step. From working with MS Access, I knew the setup I had would repeat the same info in column 1 and 2 of my table. All I really wanted to do was setup the table and make sure it worked and then try to figure out how to get the data to flow correctly. With your help, I was able to get it to output the look I wanted. Thank you. I really appreciated the fact that you said it in English and then wrote it out in PHP. It makes it much easier to interpret what you wrote. Next question, how do I get two records per row? I am having a problem finding the correct help because I don't know the correct terminology. Quote Link to comment https://forums.phpfreaks.com/topic/182672-why-wont-this-work-need-a-little-help/#findComment-964195 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.