![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi-- Well, I have progressed quite a bit with all this, but now I seem to have something wrong with my while loop. It seems that every time the script is run, it is missing either the first (or is it last??) record. What this script does is do a GET from a link as: getdbcat.php?categoryh=downloading So there are several records with that as categoryh. But when actually executed, there will always be one record missing (not displayed). I have records 1-90 as having that as a categoryh, and my database unsorted goes from 90 to 1. It is always record 90 that is missing...so I think that would be the first it sees. I believe there must be something wrong with my while statement which is repeated below: $i = 0; while($row = mysql_fetch_array($query)) { $row_class = (($i % 2) == 0) ? $colorblue : $colorwhite; echo "<tr bgcolor =\"$row_class\">"; $i++; Here's the complete script: <?php $categoryh = addslashes($_GET['categoryh']); if(empty($categoryh) ) { echo "Sorry. We couldn't find any ", $categoryh, " Category. Please try again."; } else { //connect to host $sConn = mysql_connect("host", "user", "password"); if (!$sConn) echo "Unable to connect to database server because ".mysql_error(); else { $dConn = mysql_select_db("db", $sConn); if (!$dConn) echo "Unable to connect to database because ".mysql_error(); else { //find which record has been sent by the GET $query = mysql_query ("SELECT * FROM articles WHERE categoryh='$categoryh'" ); $category = ucwords($category); $row = mysql_fetch_array($query); ?> <table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#dcdcdc"> <tr> <td bgcolor="#3d80e9"><font color="white">Drumbeat TIL Articles</font></font></td> </tr> </table> <table width="100%" border="0" cellspacing="1" cellpadding="9" bgcolor="#dcdcdc" height="90%"> <tr> <td valign="top" bgcolor="white"><b><span class="evenbigger"> <?php if($categoryh == "gettingstarted") echo "<b>"I need help ",$row[category],"!"<br><br></b>"; else { echo "<b>"I need help with ",$row[category],"!"<br><br></b>"; } } } } ?> </span></b><br> <br> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top">To navigate to other main topic areas, select a topic from the list above or click the button to the right. Click a link below to view the support document related to your query. Contents of this topic area are as follows:</td> <td valign="top"><a href="indexnew.html"><img src="/images/support-index.gif" alt="" width="108" height="31" align="right" border="0"></a></td> </tr> </table> <div align="center"> <br> <table width="90%" border="0" cellspacing="1" cellpadding="3" bgcolor="silver"> <tr> <td nowrap bgcolor="#3d80e9"><font color="white"><b>TIL #</b></font></td> <td bgcolor="#3d80e9"><font color="white"><b>Article Subject</b></font></td> <td bgcolor="#3d80e9"><font color="white"><b>Last Modified</b></font></td> </tr> <?php $colorblue = "eff3fe"; $colorwhite = "FFFFFF"; $i = 0; while($row = mysql_fetch_array($query)) { $row_class = (($i % 2) == 0) ? $colorblue : $colorwhite; echo "<tr bgcolor =\"$row_class\">"; $i++; { ?> <td> <p><?php echo $row["til_id"]; ?></p> </td> <td> <p><?php echo $row["referrence"]; ?></p> </td> <td> <p><?php echo $row["modified"]; ?></p> </td> </tr> <?php } } echo "</table>"; ?> | |||
| | #2 | ||
| in article bhr1ud$29chg$1@ID-175424.news.uni-berlin.de, Jon Kraft at jon@jonux.co.uk wrote on 8/18/03 10:20 AM: > Jeffrey Ellis wrote: > >> It seems that every time the script is run, it is missing either the first >> (or is it last??) record. >> >> <?php >> >> $categoryh = addslashes($_GET['categoryh']); >> >> if(empty($categoryh) ) { >> echo "Sorry. We couldn't find any ", $categoryh, " Category. Please try >> again."; >> } >> else { >> //connect to host >> >> $sConn = mysql_connect("host", "user", "password"); >> if (!$sConn) >> echo "Unable to connect to database server because ".mysql_error(); >> else { >> $dConn = mysql_select_db("db", $sConn); >> if (!$dConn) >> echo "Unable to connect to database because ".mysql_error(); >> else { >> >> //find which record has been sent by the GET >> >> $query = mysql_query ("SELECT * FROM articles WHERE >> categoryh='$categoryh'" ); >> $category = ucwords($category); >> $row = mysql_fetch_array($query); > > Hi Jeffrey, > > Above you get the first row, and later you start the while loop, which then > obviously starts at the second row returned. > > HTH; > JOn Hi, Jon-- Ah! okay...that explains it. However, the reason I put in the line above was so that the lines just below would work. So although now it is retrieving all the records correctly, it doesn't seem to be able to fill in the two echo statements, and so they are blank. Is there any way I can do both? <?php if($categoryh == "gettingstarted") echo "<b>"I need help ",$row[category],"!"<br><br></b>"; else { echo "<b>"I need help with ",$row[category],"!"<br><br></b>"; } Thanks again! All My Best, Jeffrey | |||
| Featured Websites | ||||
|
![]() |
| Tags: missing, record |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding record to a MYSQL DB using PHP ? | James | PHP | 1 | 07-01-2007 3:32 PM |
| UPDATE a record in MYSQL DB with PHP | James | PHP | 1 | 07-01-2007 3:32 PM |
| Random Record | Disco | PHP | 0 | 07-01-2007 3:11 PM |
| Is it possible to update a record if it does not exist? | Jeff Silverman | Database | 1 | 06-10-2007 12:21 AM |
| Am i missing something here... | Ridwan Hughes | Ebay Technical Questions | 2 | 05-30-2007 2:09 AM |
| Featured Websites | ||||
|