Forum Moderators: coopster

Message Too Old, No Replies

variable as url for other variable

         

shnoop

1:06 pm on Oct 12, 2004 (gmt 0)

10+ Year Member



Hello guys, i have a problem. In my mysql database I have a table with 4 colums. Now i need a script, which reads out this database, and creates a table with the 30 last entries in the database ordered by date, which is one column in the database. This is not very difficult, I did it this way:

<?php

$db=mysql_connect("localhost","#*$!","#*$!");
mysql_select_db("xxx", $db);
$result=mysql_query("SELECT * FROM presse ORDER BY datum DESC LIMIT 30", $db);
for($i=0; $i<mysql_num_rows($result); $i++)
{
$presse[$i]=mysql_fetch_object($result);
}
echo "<table border=\"0\">";
for($i=0; $i<mysql_num_rows($result); $i++)
{
echo "<tr>",
"<td>",
$presse[$i]->zeitung,
"</td>",
"<td>",
nl2br($presse[$i]->headline),
"</td>",
"<td>",
substr($presse[$i]->datum, 8, 2),
".",
substr($presse[$i]->datum, 5, 2),
".",
substr($presse[$i]->datum, 0, 4),
" ",
substr($presse[$i]->datum, 10),
"</td>",
"</tr>";
}

?>

This works, but it is not quite what I want. The fourth row in the db-table is the url which belongs to the set of data. I want, that when you klick on the headline, which has been given out, that you get to the url. I donīt see how i can do it and iīm not sure whether i can do it this way. I hope you can help me...

shnoop

5:56 pm on Oct 12, 2004 (gmt 0)

10+ Year Member



Is this really so difficult?

Timotheos

6:46 pm on Oct 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

Probably not so difficult I'm just trying to understand the question.

I suppose you want something like this.

"<a href=\"" . $presse[$i]->url . "\">" ,
nl2br($presse[$i]->headline),
"</a>",

shnoop

7:47 pm on Oct 12, 2004 (gmt 0)

10+ Year Member



Thank you very much, you really helped me. I'm still learning, and as it seems, i still have to learn a lot...

shnoop

8:53 pm on Oct 12, 2004 (gmt 0)

10+ Year Member



I still have a question. I want, when you click on the url, that a new window opens. I thought I could do it like this:

"<a href=\"" . $presse[$i]->url . "\" target="_blank">" ,
nl2br($presse[$i]->headline),
"</a>",

but as a consequence of that it gives me this error:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in "#*$!" on line 60

where do I have to put in the target thing?

jatar_k

9:15 pm on Oct 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you need to escape the quotes around _blank using \

"<a href=\"" . $presse[$i]->url . "\" target=\"_blank\">" ,
nl2br($presse[$i]->headline),
"</a>",