emy Posted June 16, 2009 Share Posted June 16, 2009 hello!can someone explain this code to me?I added more fields in mysql but I have to insert more echo rows in my php file, right?Is there a easy way to generate the code through mysql?Sorry..I'm such a n00b T_TALSOOOOOO I've tried incorporating several codes for splitting the pages up so u don't have 200 items in one page. Would anyone recommend a working code?Thanks in advance!! <?phpif($_GET['action'] == "delete"){if($userCheck == "admin"){$cID = $_GET['cID'];echo "Deleting Datbase ID " . $cID . "<br />";mysql_query("DELETE FROM pdf where id = '$cID'") or die(mysql_error());}else{require('error.php');error('666');}}$z = 0;$result = mysql_db_query("a2288820_data","SELECT * FROM pdf ORDER BY id");while(($row = mysql_fetch_array($result))){echo "<tr>\n";if($userCheck == "admin"){echo "<td id=\"noLinkTd\"><a href=\"?page=edit&cID=".$row[0]."\">[Edit] ".$z."</a><br />";echo " <a href=\"java script://\" onClick=\"deleteRo(".$row[0].",".$z.")\">[Remove]</a>";echo "</td>\n";}elseecho "<td>".$z."</a></td>\n";echo "<td>".$row[1]." </td>\n";echo "<td>".$row[2]." </td>\n";echo "<td sorttable_customkey=\"2008".$row[14]."01120100\">".$row[3]."</td>\n";if($row[4] != null){$day = (int)$row[4];echo "<td>".date("d",mktime(0,0,0,0,$day))."</td>\n";}elseecho "<td></td>\n";echo "<td>".$row[5]." </td>\n";echo "<td>".$row[6]." </td>\n";echo "<td>".$row[7]." </td>\n";echo "<td>".$row[8]." </td>\n";echo "<td>".$row[9]." </td>\n";echo "<td>".$row[10]." </td>\n";echo "<td>".$row[11]." </td>\n";echo "<td>".$row[12]." </td>\n";echo "<td><a href=\"".$row[13]."\">".$row[13]."</a> </td>\n";echo "</tr>\n";$z++;}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 16, 2009 Share Posted June 16, 2009 If you want to print more fields then, yeah, you need more lines to print. It will probably also be easier to refer to your fields by name instead of number, e.g. $row['id'] instead of $row[0], whatever your fields are called. If you want to split results up among pages do a search for pagination, there are a lot of topics here about it. Link to comment Share on other sites More sharing options...
emy Posted June 17, 2009 Author Share Posted June 17, 2009 ^thanks so much for the excellent tips!! May I ask how I can just change the fields to names? I can't just go in and change the [1] to [iD]..can I? I've tried just adding more rows...but when the info showed up wrong on the webpage even tho it was right in mysql..>< Link to comment Share on other sites More sharing options...
justsomeguy Posted June 17, 2009 Share Posted June 17, 2009 Yeah, you can just change the names. Make sure you quote them. $row['id'] instead of $row[id]. If you want to see all of the data in $row, you can use print_r. It should have both named and numbered elements:echo '<pre>' . print_r($row, true) . '</pre>';Change all the names and then see if you're still seeing the wrong data, you might just be using the wrong column numbers. Names are typically better than numbers because if you were using numbers and added a new column in the middle of the table you'd have to re-number the other fields in the code. Link to comment Share on other sites More sharing options...
emy Posted June 18, 2009 Author Share Posted June 18, 2009 aw, I'm getting this error:PHP Notice: Undefined index: id in xxxxxxxxxxxxxxxx on line 96 PHP Notice: Undefined index: type in D: over and over again..I only changed it to two of them. Not changing all could cause this error? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 18, 2009 Share Posted June 18, 2009 That means there's not an element called "id" in the array. Use that print_r line to see what's in the array. Link to comment Share on other sites More sharing options...
emy Posted June 22, 2009 Author Share Posted June 22, 2009 sorry..may I ask how to use the print_r line? do you mean to changeecho "<td>".$row[1]." </td>\n";to echo '<pre>' . print_r($row, true) . '</pre>'; Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2009 Share Posted June 22, 2009 You don't need to change anything, just add the new line. It will print the array structure so you can see all of the fields and data. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.