Please support our MySQL advertiser: Programming Forums
Views: 501 | Replies: 5 | Solved
![]() |
•
•
Join Date: Jan 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Hello, why wont this code give my "Rubrik" a link with its ID? I only get "www.yada.com/open.php?id="
sql Syntax (Toggle Plain Text)
<a href="skapaannons.php">Lä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); ?>
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation:
Rep Power: 2
Solved Threads: 20
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.
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?
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?
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
"Others make web sites. We make web sites work!"
•
•
Join Date: Jan 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
line 11 works fine, what I wonder is if line 12 is right to give a result on line 22, should the
give a result in
if I did the right thing with line 12 ^^
or do I need to use another "where"?
I dont understand
Thank you for the reply =)
#
$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

Thank you for the reply =)
Last edited by gatsu : Apr 27th, 2008 at 4:16 pm.
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation:
Rep Power: 2
Solved Threads: 20
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.
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.
Last edited by trudge : Apr 27th, 2008 at 5:21 pm.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
"Others make web sites. We make web sites work!"
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode