Hello, why wont this code give my "Rubrik" a link with its ID? I only get "www.yada.com/open.php?id="

<a href="skapaannons.php">L&auml;gg till annons!
</a>
<?php

$con = mysql_connect(" "," "," ");
if (!$con) {
	die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("annons", $con);
$result = mysql_query("SELECT annons.id, annons.datum, annons.rubrik, annons.pris, annons.område, annons.säljare, annons.email, annons.tele, annons.kat, annons.text, områden.plats AS område FROM annons, områden WHERE annons.område=områden.id");
$id2 = mysql_query("SELECT annons.id, annons.datum, annons.rubrik, annons.pris, annons.område, annons.säljare, annons.email, annons.tele, annons.kat, annons.text, områden.plats as annons FROM annons WHERE annons.rubrik=annons.id");

echo '<h2>Annonser</h2>';
echo '<table cellpadding="2" rules="groups" frame="box">';
echo '<thead><tr><th width="150px" align="left">Datum</th><th width="350px" align="left">Rubrik</th><th width="50px" align="left">Pris</th><th width="100px" align="left">Område</th></thead>';
echo '<tbody>';

while ($add = mysql_fetch_array($result, MYSQL_BOTH)){
  echo "<td>" . $add['datum'] . "</td>";

  echo "<td>" . '<a href="open.php?id='.urlencode($id2).'">' . $add['rubrik'] . '</a>' . "</td>";

  echo "<td>" . $add['pris'] . ":-</td>";
  echo "<td>" . $add['område'] . "</td>";
  echo '</tr>';
}
  echo "</tbody></table>";


echo "<br \>";
echo "<br \>";

mysql_close($con);

?>

I notice you have some non-standard characters in the query. You might be trying to match something from one character set to something in a different character set.

WHERE annons.område=områden.id

Make sure the correct character set (and same character set) is enabled for the whole database, each table, and the collation.

Does your query return the correct result set when you just use the command line?

line 11 works fine, what I wonder is if line 12 is right to give a result on line 22, should the

#
$id2 = mysql_query("SELECT annons.id, annons.datum, annons.rubrik, annons.pris, annons.område, annons.säljare, annons.email, annons.tele, annons.kat, annons.text, områden.plats as annons FROM annons WHERE annons.rubrik=annons.id");

give a result in

#
echo "<td>" . '<a href="open.php?id='.urlencode($id2).'">' . $add['rubrik'] . '</a>' . "</td>";

if I did the right thing with line 12 ^^
or do I need to use another "where"?
I dont understand :S

Thank you for the reply =)

Again, I have to ask: does your query work from the command line? If you are not sending the right query, then you won't get the right results.

I don't know what 'annons.område' is but you are comparing it to 'områden.id'. Are they both the same data type?

You also have 'annons.rubrik=annons.id'. Are those both the same data types?

And if all you want is $id2, why are you selecting 11 fields? Or do they all make up $id2?

Your first priority is to find out exactly what your queries contain. Print them out. Or test them from the command line before you try to get it working in your script. If you know your SQL query works, then the problem is your programming, and this is the wrong forum for that.

ok sorry but what is the command line? :S

nvm I know now ^^ will look into this more, thank you its usefull :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.