mediasix Posted November 13, 2007 Share Posted November 13, 2007 i have written a function that grabs some data from my 'mysql' database and outputs it to a page, the problem i am having is hyperlinking the outputted data, find my code below: <?php mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query ="SELECT title, content,"; $query.=" DATE_FORMAT(date, '%D %M, %Y') AS date"; $query.=" FROM weblog ORDER BY date DESC LIMIT 2"; $result=mysql_query($query); while (list($title,$content,$date) = mysql_fetch_row($result)) { echo "<a href"/weblog/weblogentry.php?=<?php echo "$title"?>"> $title </br>($date)</a>"; echo "<h5>$content</h5>"; } ?> the error i am getting is this: Parse error: syntax error, unexpected '=' in /othercontent2.php on line 10 if i take out the <a href" etc etc, the data displays fine, as soon as i try to hyperlink it breaks! please help!! thanks mediasix Quote Link to comment Share on other sites More sharing options...
shocker-z Posted November 13, 2007 Share Posted November 13, 2007 try this <?php mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query ="SELECT title, content,"; $query.=" DATE_FORMAT(date, '%D %M, %Y') AS date"; $query.=" FROM weblog ORDER BY date DESC LIMIT 2"; $result=mysql_query($query); while (list($title,$content,$date) = mysql_fetch_row($result)) { echo '<a href="/weblog/weblogentry.php?='.$title.'"> $title </br>($date)[/url]'; echo "<h5>$content</h5>"; } ?> Also your not defining a variable here weblogentry.php?= should it not be weblogentry.php?title= Regards Liam Quote Link to comment Share on other sites More sharing options...
revraz Posted November 13, 2007 Share Posted November 13, 2007 To explain what the actual problem is, you can't use double quotes inside of double quotes like that. So you have to either have single quotes inside of double quotes or double quotes inside of single quotes. If you don't have any variables inside the quotes, then either is fine, but if you do have variables, you have to use them correctly. i have written a function that grabs some data from my 'mysql' database and outputs it to a page, the problem i am having is hyperlinking the outputted data, find my code below: <?php mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query ="SELECT title, content,"; $query.=" DATE_FORMAT(date, '%D %M, %Y') AS date"; $query.=" FROM weblog ORDER BY date DESC LIMIT 2"; $result=mysql_query($query); while (list($title,$content,$date) = mysql_fetch_row($result)) { echo "<a href"/weblog/weblogentry.php?=<?php echo "$title"?>"> $title </br>($date)</a>"; echo "<h5>$content</h5>"; } ?> the error i am getting is this: Parse error: syntax error, unexpected '=' in /othercontent2.php on line 10 if i take out the <a href" etc etc, the data displays fine, as soon as i try to hyperlink it breaks! please help!! thanks mediasix Quote Link to comment Share on other sites More sharing options...
mbeals Posted November 13, 2007 Share Posted November 13, 2007 echo "<a href"/weblog/weblogentry.php?=<?php echo "$title"?>"> $title </br>($date)[/url]"; What exactly are you trying to output here? First off, you have <? ?> inside existing <? ?> tags. That isn't necessary. if you are trying to echo this? <a href="/weblog/weblogentry.php?=$title"> $title </br>($date)</a>" This construct inside your parent <? ?> tags would be: echo "<a href=\"/weblog/weblogentry.php?=".$title."\"> ".$title." </br>(".$date.")</a>"; notice that the string is broken up into literal strings (between " ") and variable strings ($title) with periods (.). Also notice that the double qoutes in the hyperlink are escaped with a \ to make php treat them as a text character. Also, for the hyperlink to work, you do need to define the variable name in the URL. weblogentry.php?=$title is malformed. weblogentry.php won't know what variable to assign $title and you will have no way of pulling it into weblogentry. If you are trying to pass $title to var title then the full line would be: echo "<a href=\"/weblog/weblogentry.php?title=".$title."\"> ".$title." </br>(".$date.")</a>"; Quote Link to comment Share on other sites More sharing options...
mediasix Posted November 13, 2007 Author Share Posted November 13, 2007 OK, with a liitle help from all of your comments and a bit of jiggery pokery i have fixed it, code as follows: <?php mysql_connect("xxxxxx","xxxxxx","xxxxxx"); mysql_select_db("xxxxxx"); $query ="SELECT title, content,"; $query.=" DATE_FORMAT(date, '%D %M, %Y') AS date"; $query.=" FROM weblog ORDER BY date DESC LIMIT 2"; $result=mysql_query($query); while (list($title,$content,$date) = mysql_fetch_row($result)) { echo '<a href="/weblog/weblogentry.php?id='.$title.'"> '.$title.' </br>('.$date.')</a>'; echo "<h5>$content</h5>"; } ?> the effect that i wanted to achieve can be found on my page www.mediasix.co.ukand look on the right hand bar, the following file is a php include. thanks for your help mediasix [tt][/tt] 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.