Jump to content

Php/mysql Help


emy
 Share

Recommended Posts

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

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

^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

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

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?

Edited by emy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...