virtuexru Posted November 6, 2006 Share Posted November 6, 2006 OK. So I have a PHP/MySQL database setup.The table in question is a table for job orders.. so basically it has ID# .. Job title, Description, etc..Now my question is how do i make a link to a job based on the title and such,so something like www.example.com/view.php?id=??but so it does the linking automatically depending on what ID/Title for the job it gets because right now I'm just pulling up the information and linking the link manually..[code] <?include 'config.php';include 'opendb.php';?> <? $query = "SELECT title, category, salary, location FROM joborder WHERE number='859'"; $result = mysql_query($query); while(list($title,$category,$salary,$location)= mysql_fetch_row($result)) { echo "<a href="example.com"><b>$title</b></a>" . " - $category" . " , $location" . ", $salary"; } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/ Share on other sites More sharing options...
Jocka Posted November 6, 2006 Share Posted November 6, 2006 $_GET['id'] .. this will pull the number after id= .. page.php?id=[b]1[/b]so then its like this$id = $_GET['id'];$query = "SELECT title, category, salary, location FROM joborder WHERE id='" . $_GET['id'] . "'"; // Or number if thats the idworks like that with the title too $_GET['title'] would get the title= from the link then "WHERE title='" . $_GET['title'] . "'" Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120572 Share on other sites More sharing options...
virtuexru Posted November 6, 2006 Author Share Posted November 6, 2006 Yea, i have something like that already..I'm talking about a previous link without id?= in the address. I want to link the ID?= into the link bar from index.php.This is the view.php?id= code <? $result = mysql_query("SELECT * FROM joborder WHERE number=$id"); $myrow = mysql_fetch_array($result); echo "<h2>Job Title: ".$myrow["title"]; echo "</h2>"; echo "<br><b>Category:</b> ".$myrow["category"]; echo "<br><b>Description:</b> ".$myrow["description"]; echo "<br><b>Salary:</b> ".$myrow["salary"]; echo "<br><b>Position:</b> ".$myrow["position"]; echo "<br><b>Location:</b> ".$myrow["location"]; echo "<p><b>Details:</b><p> ".$myrow["details"]; echo "</p></p>"; ?> Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120581 Share on other sites More sharing options...
oracle259 Posted November 6, 2006 Share Posted November 6, 2006 Im not certain if i understand exactly what ur tryin to do but here goesBasically u want the rows generated by the mysql result to be clickable by headers (title, id, description, salary, location, etc) and all these headers must point to the single id whatever that isAm i on the right track Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120588 Share on other sites More sharing options...
oracle259 Posted November 6, 2006 Share Posted November 6, 2006 if im right try this code [code]<?include 'config.php';include 'opendb.php';?> <? $trackid= trim($_REQUEST(['id']); $trackid = mysql_real_escape_string($trackid); $query = "SELECT title, category, salary, location FROM joborder WHERE number='$trackid'"; $result = mysql_query($query); while(list($id,$title,$category,$salary,$location)= mysql_fetch_row($result)) { echo "<a href="example.com?id='$id'"><b>$title</b></a>" . " - $category" . " , $location" . ", $salary"; } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120590 Share on other sites More sharing options...
virtuexru Posted November 6, 2006 Author Share Posted November 6, 2006 yea basically i have a link on the main page that has the title of a certain job in it.. then that job automatically links to the view.php?=$id page. how would I go about doing that. Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120591 Share on other sites More sharing options...
oracle259 Posted November 6, 2006 Share Posted November 6, 2006 correct $trackid= trim($_REQUEST(['id']); to[code] $trackid= trim($_REQUEST(['id']));[/code] Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120593 Share on other sites More sharing options...
virtuexru Posted November 6, 2006 Author Share Posted November 6, 2006 I get a Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' on this line:echo "<a href="example.com?id='$id'"><b>$title</b></a>" . " - $category" . " , $location" . ", $salary"; Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120596 Share on other sites More sharing options...
oracle259 Posted November 6, 2006 Share Posted November 6, 2006 use this[code]echo "<a href='example.com?id=$id'>$title</a>" . "<a href='example.com?id=$id'>$category</a>" . "<a href='example.com?id=$id'>$location</a>" . "<a href='example.com?id=$id'>$salary</a>";[/code] Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120615 Share on other sites More sharing options...
oracle259 Posted November 6, 2006 Share Posted November 6, 2006 sorry that should be[code]echo "<a href='example.com?id=$id'>$title</a>" . "<a href='example.com?id=$id'>$category</a>" . "<a href='example.com?id=$id'>$location</a>" . "<a href='example.com?id=$id'>$salary</a>";[/code] Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120617 Share on other sites More sharing options...
virtuexru Posted November 6, 2006 Author Share Posted November 6, 2006 Thanks, now another quick question.The $_REQUEST['id'] part, requests the id from where? Sorry if it sounds stupid. Trying to learn :-P. Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120624 Share on other sites More sharing options...
oracle259 Posted November 6, 2006 Share Posted November 6, 2006 This link [url=http://www.php.net/manual/en/reserved.variables.php]http://www.php.net/manual/en/reserved.variables.php[/url] can explain better i think. But basically it allows you to retrieve the variable $id whether using Post in the case of a form or Get in the case of a url like your doing Link to comment https://forums.phpfreaks.com/topic/26369-newbie-here-need-help-linking/#findComment-120664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.