me1000 Posted March 5, 2006 Share Posted March 5, 2006 ok I have a my sql table set up as so...+---+---------------+---------------+---------+| ID | PAGE_TITLE | PAGE_TYTLE | Conent |+---+---------------+---------------+---------+| 1 | title | type | Conent | +---+---------------+---------------+---------+| 2 | title2 | type2 | Conent | +---+---------------+---------------+---------+in doing a mysql query select * from $tablenameso I want to have a page that sets up a simple table that show the page Title, then the ID next to it in a diffrent column. beside all that I want another collumn that says edit in every row. this will link to page.php?pag_id=2where 2 is the ID of the page. i am clueless on how to do this. though, i tried to explain it as well as I could I hope you understand.how would you do it? Right now i dont have any idea!!!Thanks Quote Link to comment Share on other sites More sharing options...
SieRobin Posted March 6, 2006 Share Posted March 6, 2006 Use a while loop, and make the query be ordered by ASC or DESC meaning, Ascending or Descending. Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 thanks for that heres what I came up with, only thing is it doesnt work! lol [code]<?require_once ("config.php");$sql = "SELECT ID, PAGE_TITLE, PAGE_TYPEFROM $sTableNameORDER BY PAGE_TYPE DESC";$sql_result = mysql_query($sql); echo "<TABLE BORDER=1>";echo "<TR><TH>Page Type </TH><TH>Page Title </TH><TH>Page ID </TH>";while ($row = mysql_fetch_array($sql_result)) {$page_id = $row["ID"];$page_title = $row["PAGE_TITLE"];$page_type = $row["PAGE_TYPE"];echo "<TR><TD>$page_type</TD><TD>$page_title</TD><TD>$page_id</TD></TR>";}echo "</TABLE>";?>[/code]See anything wrong?Never Mind I fixed it!!!thanks for all your help! Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 Ok now I need help with the link to edit [code] $edit = 'echo = "<a href ="cms.php?page_id=$page_id">Edit Page</a>" '[/code]Im not sure where I should add the quotes and what type of quotes to add, since there is a variable in the URL{edit}gettin closer[code]$edit = '<a href ="cms.php?page_id=$page_id">Edit Page</a> '[/code]but no cigarthis is my full page if it helps.[code]<?require_once ("config.php");$sql = "SELECT ID, PAGE_TITLE, PAGE_TYPEFROM $sTableNameORDER BY PAGE_TYPE ASC";$sql_result = mysql_query($sql); echo "<TABLE BORDER=1>";echo "<TR><TH>Page Type </TH><TH>Page Title</TH><TH>Page ID</TH><TH>Edit Page</TH>";while ($row = mysql_fetch_array($sql_result)) {$page_id = $row["ID"];$page_title = $row["PAGE_TITLE"];$page_type = $row["PAGE_TYPE"];$edit = '<a href ="cms.php?page_id='$page_id'">Edit Page</a>';echo "<TR><TD>$page_type</TD><TD>$page_title</TD><TD>$page_id</TD><TD>$edit</TD></TR>";}echo "</TABLE>";?>[/code] Quote Link to comment Share on other sites More sharing options...
play_ Posted March 6, 2006 Share Posted March 6, 2006 make the table outside the loop, then inside, make the columns and rowstry this$edit = '<a href ="cms.php?page_id='.$page_id.'">Edit Page</a> ' Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 Thanks for that it works now. :)now its time to make it more complex lol! Thanks again! Quote Link to comment Share on other sites More sharing options...
play_ Posted March 6, 2006 Share Posted March 6, 2006 lol, anytime. Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 ok instead of page type being a number which it is in the database, I want to convert it to text. Im using a if statment for this[code]if ($page_type == "1") { echo "Home"; } else if ($page_type == "2") { echo "Series"; } else if ($page_type == "3") { echo "Movies"; } else if ($page_type == "4") { echo "Special"; } else if ($page_type == "5") { echo "Gaming"; } else { echo "unknown"; }[/code]now the problem is that im using [code]echo "<TR><TD>$page_type</TD><TD>$page_title</TD><TD>$page_id</TD><TD>$edit</TD></TR>";[/code]to show the each row. yet that doesnt get me much if you know what I mean.how do I do this?? I will probably need to change the variable name in the table. Quote Link to comment Share on other sites More sharing options...
play_ Posted March 6, 2006 Share Posted March 6, 2006 change this:if ($page_type == "1")to this:if ($page_type == 1) Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 ok I chaged it now the if statments working right but its not putting it in the table right. Quote Link to comment Share on other sites More sharing options...
play_ Posted March 6, 2006 Share Posted March 6, 2006 Im not sure what your problem is.You got all those IF statements to work but removing the"" from each number, right?What was the other problem? Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 ok inside the mysql table the values for PAGE_TYPE are numbers, the if statment converts them all to text but I want them to show up in the table heres my page again,[code]<?require_once ("config.php");$sql = "SELECT ID, PAGE_TITLE, PAGE_TYPEFROM $sTableNameORDER BY PAGE_TYPE ASC";$sql_result = mysql_query($sql); echo "<TABLE BORDER=1>";echo "<TR><TH>Page Type </TH><TH>Page Title</TH><TH>Page ID</TH><TH>Edit Page</TH>";while ($row = mysql_fetch_array($sql_result)) {$page_id = $row["ID"];$page_title = $row["PAGE_TITLE"];$page_type = $row["PAGE_TYPE"];$edit = '<a href ="cms.php?page_id='.$page_id.'">Edit Page</a>';// change page type #'s to wordsif ($page_type == 1) { echo "Home"; } else if ($page_type == 2) { echo "Series"; } else if ($page_type == 3) { echo "Movies"; } else if ($page_type == 4) { echo "Special"; } else if ($page_type == 5) { echo "Gaming"; } else { echo "unknown"; }echo "<TR><TD>$page_type</TD><TD>$page_title</TD><TD>$page_id</TD><TD>$edit</TD></TR>";}echo "</TABLE>";?>[/code]I think the if statment may need to replace the $page_type variable in the echo "<TR><TD>$page_type</TD><TD>$page_title</TD><TD>$page_id</TD><TD>$edit</TD></TR>";But im not sure on how to add it to there Quote Link to comment Share on other sites More sharing options...
play_ Posted March 6, 2006 Share Posted March 6, 2006 Try this:<?require_once ("config.php");$sql = "SELECT ID, PAGE_TITLE, PAGE_TYPEFROM $sTableNameORDER BY PAGE_TYPE ASC";$sql_result = mysql_query($sql);echo "<TABLE BORDER=1>";echo "<TR><TH>Page Type </TH><TH>Page Title</TH><TH>Page ID</TH><TH>Edit Page</TH>";while ($row = mysql_fetch_array($sql_result)) {$page_id = $row["ID"];$page_title = $row["PAGE_TITLE"];$page_type = $row["PAGE_TYPE"];$edit = '<a href ="cms.php?page_id='.$page_id.'">Edit Page</a>';// change page type #'s to words$new_type = NULL;if ($page_type == 1) { $new_type = "Home" echo $new_type; } else if ($page_type == 2) { $new_type = "Series" echo $new_type; } else if ($page_type == 3) { $new_type = "Movies" echo $new_type; } else if ($page_type == 4) { $new_type = "Special" echo $new_type; } else if ($page_type == 5) { $new_type = "Gaming" echo $new_type; } else { $new_type = "Unknown" echo $new_type; }echo "<TR><TD>$new_type</TD><TD>$page_title</TD><TD>$page_id</TD><TD>$edit</TD></TR>";}echo "</TABLE>";?> Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 im getting a phrase error on line 25.Parse error: parse error, unexpected T_ECHO in /htdocs/cms/pages.php on line 25line 25 is the firstecho $new_type; Quote Link to comment Share on other sites More sharing options...
play_ Posted March 6, 2006 Share Posted March 6, 2006 Oh sorry.I forgot to put ; after some lines$new_type = "Home"should be$new_type = "Home";and for all the others below that too lol. sorry Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 Thanks A million that fixed it. I got to remember that now. lolI really appreciate your help! Quote Link to comment Share on other sites More sharing options...
play_ Posted March 6, 2006 Share Posted March 6, 2006 Anytime.While im at it, let me give you some more advice.Instead of using a bunch of IF/ELSE IF statements like you did, use the SWITCH statement.I'm not sure if it makes your code faster or not, but it makes it easier to read and apparently, its more programmer-like (in other words, looks less newb :) )so instead of:[code]if ($page_type == 1) {$new_type = "Home"echo $new_type;} else if ($page_type == 2) {$new_type = "Series"echo $new_type;} else if ($page_type == 3) {$new_type = "Movies"echo $new_type;} else if ($page_type == 4) {$new_type = "Special"echo $new_type;} else if ($page_type == 5) {$new_type = "Gaming"echo $new_type;} else {$new_type = "Unknown"echo $new_type;}[/code]You could/should have:[code]$new_type = NULL;switch ($page_type) { case 1: $new_type = "Home"; echo $new_type; break; case 2: $new_type = "Series"; echo $new_type; break; [/code]and you could finish it off with the others :) Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 6, 2006 Author Share Posted March 6, 2006 Cool Thanks Ill keep that in mind!!! Quote Link to comment 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.