Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding specifics to a hyperlink 2

Status
Not open for further replies.

sinbadly

Technical User
Mar 16, 2006
126
GB
Hyperlinks I have in regular use are rather like this:
Code:
<a href="the_url/pix/1xtra.php?id=18">
Is there a way to be more specific? Not just to get the article (id '18') to appear on the website, but to add code to the url to say I want article id 18 to show the mysql table fields head, byline, story,(for instance) please?
 
sure just add criteria to the query string and test it in your php code

Code:
<a href="the_url/pix/1xtra.php?id=18[red]&view=shortform">

Code:
<?php
$view = isset($_GET['view']) ? $_GET['view'] : "";
switch ($view){
 case "shortform":
    $sql = "Select field1, field2, field3 from table where id=".mysql_escape_string($_GET['id'];
    break;
  case "longform":
   $sql = "select * from table where id= ".mysql_escape_string($_GET['id'];
   break;
  default:
   //something else
}
 
Looks good, Justin. Thanks very much. Will play with it tonight. Cheers.
 
I spent some time with this, but I couldn't find out to make it work. This is where it would be used - this abbreviated code.I'd be very grateful if could show me how the switch function etc would be used here, pls?

Code:
$result = @mysql_query("SELECT * FROM 1fp WHERE story_num = 1");

							while( $row = mysql_fetch_array($result))  
{
echo '<br><div class="date2">Dateline: '

. $row["ud"] 							
. '&nbsp;</div><br>'						
. '<br><h3 class="fp">'	
. $row["sub"] 
. '</h3>'							
. '<h1 class="front">' 						
. $row["head"] 							
. ' </h1>'						

. $row["story"]							
. ' <a href="pix/1xtra.php?id='

. $row["readmore"]

. '" title="The story continues here.">Please read on &raquo;</a></p>';
Justin, is the [red] in the url to be [read]? Many thanks for your help with this.
 
the [red] part is just a TGML construct for this forum to make text red, but Jpadie forgot to add the closing tag.

so [ignore][red]Red Text[/red][/ignore] would yield [red]Red Text [/red].

As for your other question, you'll have to check the new variable and alter you query accordingly:
Code:
[green]\\check if the view variable exists and alter query if it does.[/green]
if(isset($_GET['view])){
$query="SELECT field1,field2,field3 where id=" . $_GET['id'] . " ORDER BY " . $_GET['view'];  
}

else{
$query="SELECT field1,field2,field3 WHERE id=" . $_GET['id'] ;
}

Depending on what you add to the link is what you check for and how you construct your query. or output data.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ah - i'd assumed that the view was not a search order construct but a switch to retrieve a smaller number of fields.

but vacunita's point remains whichever construct is correct: you need to test the variable and then use the result of the test to construct your query. you may then need to test again to insert the query results into your page template.
 
Thanks, Justin, thanks, Vacunita. Back to the drawing board to try this. Very grateful for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top