porta325 Posted June 11, 2007 Share Posted June 11, 2007 Hey, i'm sure it looks childish for you but i'm in the beginning and i couldn't find something i could understand on this topic anywhere.The ideea is that i want to make some kind of directory. I have the code that lists entries from a database but i don't know how to make all those entries links that point to other pages. Basicaly, i need every entry(category) to point to a new page that will contain data about that category. <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); //select table $result = mysql_query ("SELECT * FROM countries"); //get entries $row = mysql_fetch_array ($result); //print result while ($row = mysql_fetch_array ($result)){ echo $row ['Country']." <br>"; } ?> This is where i am and where i am stuck.All this part works just fine.I have an Id assigned to every entry so if you can help me move on i would apreciate. I just need to know what other files i need to create and how the href tag should look like. Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/ Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); //select table $result = mysql_query ("SELECT * FROM countries"); //get entries $row = mysql_fetch_array ($result); //print result while ($row = mysql_fetch_array ($result)){ echo "<a href=\"showlinks.php?id={$row["id"]}\">{$row["name"]}</a><br />"; "; } ?> Assuming you have a "name" field. Then to show them in showlinks.php, use $_GET["id"] in your query Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272536 Share on other sites More sharing options...
porta325 Posted June 11, 2007 Author Share Posted June 11, 2007 Assuming you have a "name" field. Then to show them in showlinks.php, use $_GET["id"] in your query Smiley The name field is "Country". I'm not sure though how to use $_GET["id"] in my query and i'm not sure what showlinks.php should contain. Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272549 Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 showlinks.php demo: <?php if(is_numeric($_GET["id"]) { $id = $_GET["id"]; } if(!isset($id)) { die("Invalid ID"); } $query = mysql_query("SELECT * FROM table WHERE categoryid = '{$id}'") or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { // Output... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272559 Share on other sites More sharing options...
porta325 Posted June 11, 2007 Author Share Posted June 11, 2007 After 8 hours diggin it's hard to understand. I would apreciate the simplest working model you can provide me with the simplest database you can immagine. Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272576 Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 You have it all there for you! All you need to do is shove a few echos in the while() loop and change the table names in the query and Bob's your uncle! Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272580 Share on other sites More sharing options...
porta325 Posted June 11, 2007 Author Share Posted June 11, 2007 <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); if(is_numeric($_GET["id"]) { $id = $_GET["id"]; } if(!isset($id)) { die("Invalid ID"); } $query = mysql_query("SELECT * FROM countries WHERE Country = '{$id}'") or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { // Output... } ?> Index works great, i still have a problem with if(is_numeric($_GET["id"]) { $id = $_GET["id"]; } if(!isset($id)) { die("Invalid ID"); } I get an error and i don't know why, i'm not familiar with that function. Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272596 Share on other sites More sharing options...
chigley Posted June 11, 2007 Share Posted June 11, 2007 Which error do you get? Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272597 Share on other sites More sharing options...
porta325 Posted June 11, 2007 Author Share Posted June 11, 2007 Parse error: syntax error, unexpected '{' in C:\wamp\www\showlinks.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-272598 Share on other sites More sharing options...
porta325 Posted June 12, 2007 Author Share Posted June 12, 2007 Index.php <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); //select table $result = mysql_query ("SELECT * FROM countries"); //get entries $row = mysql_fetch_array ($result); //print result while ($row = mysql_fetch_array ($result)){ $id=$row["Id"]; $status=$row["Status"]; $country=$row["Country"]; echo "<a href=\"showlinks.php?id={$id}\">{$country}</a><br />"; } ?> Showlinks.php <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); if(!isset($id)) { die("Invalid ID"); } $id = $_GET["id"]; $query = mysql_query("SELECT * FROM links WHERE Id = '{$id}'") or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { // Output... $id1=$row["id"]; echo "$id1"; } ?> I'm not sure why it says INVALID ID, as i see it the id's from both tables are connected right. Any ideeas ? Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-273172 Share on other sites More sharing options...
sasa Posted June 12, 2007 Share Posted June 12, 2007 Index.php <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); //select table $result = mysql_query ("SELECT * FROM countries"); //get entries //$row = mysql_fetch_array ($result); <--- remove this line //print result while ($row = mysql_fetch_array ($result)){ $id=$row["Id"]; $status=$row["Status"]; $country=$row["Country"]; echo "<a href=\"showlinks.php?id={$id}\">{$country}[/url] "; } ?> Showlinks.php <?php //connect mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("directory") or die(mysql_error()); $id = $_GET['id']; // <---- add this line if(!isset($id)) { die("Invalid ID"); } $id = $_GET["id"]; $query = mysql_query("SELECT * FROM links WHERE Id = '{$id}'") or die(mysql_error()); while($row = mysql_fetch_assoc($query)) { // Output... $id1=$row["id"]; echo "$id1"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-273250 Share on other sites More sharing options...
porta325 Posted June 12, 2007 Author Share Posted June 12, 2007 Thx alot, solved this one, now i'm fighting with another.I can't asociate a column from first table with one from the second.Meaning that every category in first column has an id associated, id that i have to associate with entries from the second table that corespond to the categories from the first table but witch are positioned random. Quote Link to comment https://forums.phpfreaks.com/topic/55130-solved-dynamic-links/#findComment-273267 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.