This is a discussion on problem calling by unique id from database in php within the alt.comp.lang.php forums, part of the PHP Programming Forums category; ok, so I have this code: a href=search.php?ID=",$i[0]," (I took out the greater ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
ok, so I have this code:
a href=search.php?ID=",$i[0]," (I took out the greater than less than cause I don't know how it would show up in some news readers) my problem is that lets say ID=5 it will call everything in my database with a 5 in the ID (ie. 5, 15, 25, etc.) Can anyone help me get passed this? TIA, Baker |
|
|||
|
"Vincent J. Gullotta" <Vin@WiFidirect.com> wrote in message
news:D5ERb.20958$w41.11121933@news4.srv.hcvlny.cv. net... > ok, so I have this code: > > a href=search.php?ID=",$i[0]," > > (I took out the greater than less than cause I don't know how it would show > up in some news readers) > > my problem is that lets say ID=5 > > it will call everything in my database with a 5 in the ID (ie. 5, 15, 25, > etc.) Can anyone help me get passed this? > > TIA, > Baker > > > nevermind, I figured it out. stupid % sign |
|
|||
|
On 27-Jan-2004, "Vincent J. Gullotta" <Vin@WiFidirect.com> wrote: > a href=search.php?ID=",$i[0]," > > (I took out the greater than less than cause I don't know how it would > show > up in some news readers) > > my problem is that lets say ID=5 > > it will call everything in my database with a 5 in the ID (ie. 5, 15, 25, > etc.) Can anyone help me get passed this? You need to show us the code. Assuming your SELECT is coded correctly and you column is defined correctly, it only return the records with a id column of 5 $sql = 'select ... where id='.$_GET['ID']; // I know about sql injection, this is just an example if you code "where id like '5' " you will have problems, but why would you do it that way? -- Tom Thackrey www.creative-light.com tom (at) creative (dash) light (dot) com do NOT send email to jamesbutler@willglen.net (it's reserved for spammers) |
|
|||
|
I'm not the best at php yet. I'm still learning the get command and stuff. I
was never a great programmer, although I kinda like it, so I guess you could consider me a dangerous programmer :) I have two tables, and two queries on one page, and if you look at the second table created, you'll see where it says: echo "<td><small><center><a href=\"", $i[2], "\" target=\"_blank\">Link ID #", $i[4], "</a></small></td>"; what I would like to do is have it pull $i[3] from the first query and put it where I have $i[4] in the second query, but the problem is that they are while loops so I can't just write $i[3] into a variable and place it in the second while loop. Any ideas? here's what all the code looks like: ###################################### #query the db $query = "SELECT * FROM links ORDER BY ID"; $result = mysql_query($query) or die(mysql_error()); #display column titles echo "<table border align=center>"; echo "<tr>"; echo "<td><center><small><b>Admin</b></small></td>"; echo "<td><center><small><b>ID</b></small></td>"; echo "<td><center><small><b>LINK</b></small></td>"; echo "<td><center><small><b>CODE</b></small></td>"; echo "</tr>"; #display results while($i = mysql_fetch_row($result)) { echo "<tr>"; echo "<td><small><a href=search.php?ID=",$i[0],">edit</a> | "; echo "<a href=delete.php?ID=",$i[0],">delete</a></small></td>"; echo "<td><small><center>", $i[0], "</small></td>"; echo "<td><small><center><a href=",$i[1],">", $i[3], "</a></small></td>"; echo "<td><small><a href=\"http://www.vjg.cc/mylinks/link.php?un=%n&ln=", $i[0], "\">", $i[2], "</a></small>"; echo "</tr>"; } echo "</table><br>"; #query the db $query = "SELECT * FROM users ORDER BY ID DESC"; $result = mysql_query($query) or die(mysql_error()); #display column titles echo "<table border align=center>"; echo "<tr>"; echo "<td><center><small><b>Admin</b></small></td>"; echo "<td><small><center><b>ID</b></small></td>"; echo "<td><small><center><b>USERNAME</b></small></td>"; echo "<td><small><center><b>LINK</b></small></td>"; echo "<td><small><center><b>Date/Time</b></small></td>"; echo "</tr>"; #display results while($i = mysql_fetch_row($result)) { echo "<tr>"; echo "<td><small><a href=deleteuser.php?ID=",$i[0],">delete</a></small></td>"; echo "<td><small><center>", $i[0], "</small></td>"; echo "<td><small><center>", $i[1], "</small></td>"; echo "<td><small><center><a href=\"", $i[2], "\" target=\"_blank\">Link ID #", $i[4], "</a></small></td>"; echo "<td><small><center>", $i[3], "</small></td>"; echo "</tr>"; } echo "</table>"; ?> ############################### "Tom Thackrey" <use.signature@nospam.com> wrote in message news:9vERb.16892$wa4.14639@newssvr27.news.prodigy. com... > > On 27-Jan-2004, "Vincent J. Gullotta" <Vin@WiFidirect.com> wrote: > > > a href=search.php?ID=",$i[0]," > > > > (I took out the greater than less than cause I don't know how it would > > show > > up in some news readers) > > > > my problem is that lets say ID=5 > > > > it will call everything in my database with a 5 in the ID (ie. 5, 15, 25, > > etc.) Can anyone help me get passed this? > > You need to show us the code. Assuming your SELECT is coded correctly and > you column is defined correctly, it only return the records with a id column > of 5 > $sql = 'select ... where id='.$_GET['ID']; // I know about sql injection, > this is just an example > > if you code "where id like '5' " you will have problems, but why would you > do it that way? > > -- > Tom Thackrey > www.creative-light.com > tom (at) creative (dash) light (dot) com > do NOT send email to jamesbutler@willglen.net (it's reserved for spammers) |
|
|||
|
On 27-Jan-2004, "Vincent J. Gullotta" <Vin@WiFidirect.com> wrote:
> > I have two tables, and two queries on one page, and if you look at the > second table created, you'll see where it says: > > echo "<td><small><center><a href=\"", $i[2], "\" target=\"_blank\">Link ID > #", $i[4], "</a></small></td>"; > > what I would like to do is have it pull $i[3] from the first query and put > it where I have $i[4] in the second query, but the problem is that they > are > while loops so I can't just write $i[3] into a variable and place it in > the > second while loop. Any ideas? > here's what all the code looks like: > > ###################################### > #query the db > $query = "SELECT * FROM links ORDER BY ID"; > $result = mysql_query($query) > or die(mysql_error()); > > #display column titles > echo "<table border align=center>"; > echo "<tr>"; > echo "<td><center><small><b>Admin</b></small></td>"; > echo "<td><center><small><b>ID</b></small></td>"; > echo "<td><center><small><b>LINK</b></small></td>"; > echo "<td><center><small><b>CODE</b></small></td>"; > echo "</tr>"; > > #display results > while($i = mysql_fetch_row($result)) { > echo "<tr>"; > echo "<td><small><a href=search.php?ID=",$i[0],">edit</a> | "; > echo "<a href=delete.php?ID=",$i[0],">delete</a></small></td>"; > echo "<td><small><center>", $i[0], "</small></td>"; > echo "<td><small><center><a href=",$i[1],">", $i[3], "</a></small></td>"; > echo "<td><small><a > href=\"http://www.vjg.cc/mylinks/link.php?un=%n&ln=", > $i[0], "\">", $i[2], "</a></small>"; > echo "</tr>"; > } > echo "</table><br>"; > > #query the db > $query = "SELECT * FROM users ORDER BY ID DESC"; > $result = mysql_query($query) > or die(mysql_error()); > > #display column titles > echo "<table border align=center>"; > echo "<tr>"; > echo "<td><center><small><b>Admin</b></small></td>"; > echo "<td><small><center><b>ID</b></small></td>"; > echo "<td><small><center><b>USERNAME</b></small></td>"; > echo "<td><small><center><b>LINK</b></small></td>"; > echo "<td><small><center><b>Date/Time</b></small></td>"; > echo "</tr>"; > > #display results > while($i = mysql_fetch_row($result)) { > echo "<tr>"; > echo "<td><small><a > href=deleteuser.php?ID=",$i[0],">delete</a></small></td>"; > echo "<td><small><center>", $i[0], "</small></td>"; > echo "<td><small><center>", $i[1], "</small></td>"; > echo "<td><small><center><a href=\"", $i[2], "\" target=\"_blank\">Link ID > #", $i[4], "</a></small></td>"; > echo "<td><small><center>", $i[3], "</small></td>"; > echo "</tr>"; > } > echo "</table>"; > ?> > ############################### You could us a join to solve the problem: #query the db $query = "SELECT * FROM users,links where users.ID=links.ID ORDER BY users.ID DESC"; $result = mysql_query($query) or die(mysql_error()); #display column titles echo "<table border align=center>"; echo "<tr>"; echo "<td><center><small><b>Admin</b></small></td>"; echo "<td><small><center><b>ID</b></small></td>"; echo "<td><small><center><b>USERNAME</b></small></td>"; echo "<td><small><center><b>LINK</b></small></td>"; echo "<td><small><center><b>Date/Time</b></small></td>"; echo "</tr>"; #display results while($i = mysql_fetch_row($result)) { echo "<tr>"; echo "<td><small><a href=deleteuser.php?ID=",$i[0],">delete</a></small></td>"; echo "<td><small><center>", $i[0], "</small></td>"; echo "<td><small><center>", $i[1], "</small></td>"; echo "<td><small><center><a href=\"", $i[2], "\" target=\"_blank\">Link ID #", $i[3+$number_of_columns_in_user_table], "</a></small></td>"; echo "<td><small><center>", $i[3], "</small></td>"; echo "</tr>"; } echo "</table>"; PS Even though it's slightly more efficient to use numeric subscripts to access the arrays returned by mysql, it makes your program hard to read and maintain. I would encourage you to use the column names (e.g. $i['ID']). Also, $i is not a very descriptive variable name. -- Tom Thackrey www.creative-light.com tom (at) creative (dash) light (dot) com do NOT send email to jamesbutler@willglen.net (it's reserved for spammers) |