User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 375,221 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,227 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 339 | Replies: 5 | Solved
Reply
Join Date: Jan 2007
Posts: 5
Reputation: gatsu is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gatsu gatsu is offline Offline
Newbie Poster

to make a link

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



  1. <a href="skapaannons.php">L&auml;gg till annons!
  2. </a>
  3. <?php
  4.  
  5. $con = mysql_connect(" "," "," ");
  6. IF (!$con) {
  7. die('Could not connect: ' . mysql_error());
  8. }
  9.  
  10. $db_selected = mysql_select_db("annons", $con);
  11. $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");
  12. $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");
  13.  
  14. echo '<h2>Annonser</h2>';
  15. echo '<table cellpadding="2" rules="groups" frame="box">';
  16. 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>';
  17. echo '<tbody>';
  18.  
  19. while ($add = mysql_fetch_array($result, MYSQL_BOTH)){
  20. echo "<td>" . $add['datum'] . "</td>";
  21.  
  22. echo "<td>" . '<a href="open.php?id='.urlencode($id2).'">' . $add['rubrik'] . '</a>' . "</td>";
  23.  
  24. echo "<td>" . $add['pris'] . ":-</td>";
  25. echo "<td>" . $add['område'] . "</td>";
  26. echo '</tr>';
  27. }
  28. echo "</tbody></table>";
  29.  
  30.  
  31. echo "<br \>";
  32. echo "<br \>";
  33.  
  34. mysql_close($con);
  35.  
  36. ?>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 174
Reputation: trudge is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: to make a link

  #2  
Apr 27th, 2008
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?
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Jan 2007
Posts: 5
Reputation: gatsu is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gatsu gatsu is offline Offline
Newbie Poster

Re: to make a link

  #3  
Apr 27th, 2008
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

Thank you for the reply =)
Last edited by gatsu : Apr 27th, 2008 at 3:16 pm.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 174
Reputation: trudge is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: to make a link

  #4  
Apr 27th, 2008
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.
Last edited by trudge : Apr 27th, 2008 at 4:21 pm.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Jan 2007
Posts: 5
Reputation: gatsu is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gatsu gatsu is offline Offline
Newbie Poster

Re: to make a link

  #5  
Apr 27th, 2008
ok sorry but what is the command line?
Reply With Quote  
Join Date: Jan 2007
Posts: 5
Reputation: gatsu is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gatsu gatsu is offline Offline
Newbie Poster

Re: to make a link

  #6  
Apr 27th, 2008
nvm I know now ^^ will look into this more, thank you its usefull
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 3:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC