Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

linking sql statement results

Options
  • 09-03-2005 8:02pm
    #1
    Registered Users Posts: 4,478 ✭✭✭


    this is probably very simple but its something i havent covered so hope you can help.

    im using php and mysql. the page in question is showing all jobs in my db. it shows the title, location, date posted and amount of views. the list can be searched and sorted.

    what i want to do is have a link on the title of each record displayed, linking to that jobs details.

    so for example user see's a title of "cashier job in supermarket", i want the user to be able to click the title and see more details about this job.

    any help appreciated!


Comments

  • Registered Users Posts: 2,031 ✭✭✭colm_c


    You'll need to have 2 things in place for this to work, the first is to have an Auto Number field, usually the ID or job_ID.

    The second is to have another page to hold the details of the job. This will pull out the information from the table depending on what ID is passed to it.

    So in the page with the list of jobs (lets call it index.php) the html link would be something like detail.php?jobID=xxx - where the xxx is the Auto Number mentioned above. Then just reference the ID in the select statement (e.g. WHERE ID = '$jobID')

    Hope this helps!


  • Registered Users Posts: 4,478 ✭✭✭wheres me jumpa


    yeah thats a big help, ive been googling to and found a few bits of code but im not sure how to use it with mine. how do i include it around the variable row?

    '</td><td align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">', $row[9], '</td></tr>';

    i should add this is an echo statement from my while loop.


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    assuming your sql statement is similiar to this
    require ("db_inc.php");
    
    $sql = "SELECT ID, HEADLINE FROM news ORDER BY ORDER_DATE DESC";
    $sql_result = mysql_query($sql, $connection) or die ("Couldnt execute query");
    while ($row = mysql_fetch_array($sql_result)) {
    $headline = $row["HEADLINE"];
    $id = $row["ID"];
    $i2 = stripslashes($headline);
    echo "<LI><a href=\"show_news.php?id=$id\" class=\"sub_nav\" title=\"home\">$i2</a>";
    }
    


    and then on show_news.php or whatever have the following code
    require ("db_inc.php");
    
    $id=$HTTP_GET_VARS['id'];
    
    $get_news = "SELECT * FROM news WHERE ID = \"$id\"";
    
    $news_result = mysql_query($get_news) or die ("Couldnt get news!");
    
    if ($num_rows == "0") {
    	echo "<span class=\"sub_nav\">There is no news</span>";
    	} else {
    	
    	while ($row = mysql_fetch_array($news_result)) {
    		$headline = $row["HEADLINE"];
    		$body = $row["BODY"];
    		$writer = $row["WRITER"];
    		$date_added2 = $row["DISPLAY_DATE"];
    		$body2 = stripslashes($body);
    		$headline2 = stripslashes($headline);
    	echo "
    <span class=\"sub_nav\"><a href=\"index.php\" class=\"sub_nav\" title=\"home\">home</a> > <a href=\"news.php\" class=\"sub_nav\" title=\"home\">news</a> >  $headline2</span>
    <p></p>
    <span class=\"sub_nav\">
    	<B>$headline2</B><BR>
    	<P>
    	$body2
    	<P>
    	<A HREF=\"news.php\" class=\"sub_nav\">View all News</A>
    	";
    	}
    
    }
    


  • Registered Users Posts: 4,478 ✭✭✭wheres me jumpa


    thanks guys, that was a big help, changed the code to suit and worked perfectly. its that not difficult after all, just wasnt sure where to begin!


Advertisement