Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

dynamic Links!?

Codes here !

Moderators: macek, egami, gesf

dynamic Links!?

Postby php-punk » Wed May 14, 2003 9:20 am

right - i'm creating a Punk E-zine and for the reviews i the links to be created from the datebase -

EG:

http://www.mysite.com/review.php?id=1

that how i want the links to be, so far i am half way there, with the result:

http://www.mysite.com/review.php?id="1

i dont know why the quotation mark is there but i cant get past it, the code i have is as follows:

Code: Select all

<?PHP

$c = mysql_connect(localhost,"","") or die ("Sorry unable to connect to the database at point 1".mysql_error());

$db = mysql_select_db(revs,$c) or die("Sorry unable to connect to the database at point 1.5".mysql_error());

$query = "SELECT * FROM news";

$result = mysql_query($query) or die("Sorry unable to connect to the database at point 2".mysql_error());


echo("<font color=\"#000000\" face=\"Geneva, Arial, Helvetica, san-serif\"><h1>Current Reviews</h1></font>");

while ($row = mysql_fetch_array($result))
{
   echo(" ");
   echo("<table celpadding=\"1\" cellspacing=\"1\">");
      echo("<tr>");
         echo("<td><font color=\"#FFFFFF\">");
         echo("<a href=\"http://www.mysite.com/b-rev.php?id=3".$row["id"].">".$row["title"]."</a></font></td>");
      echo("</a>");
      echo("</tr>");
      

      echo("<tr>");
         echo("<td> Posted By".$row["user"]."<i>Posted on".$row["date"]."</i></td>");
         
      echo("</tr>");

      echo("</table>");
}
   
   
   mysql_free_result($result);
?>


any help greatly appreciated
php-punk
New php-forum User
New php-forum User
 
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk

Postby Joan Garnet » Wed May 14, 2003 10:54 am

Weird...
Just a note, you don't need the "( )" when you echo anything.

It should work :?:
Code: Select all
echo "<a href=\"http://www.mysite.com/b-rev.php?id=" . $row["id"] . ">" . $row["title"] . "</a></td>";

If $row["id"] has a value of 1 it should output

http://www.mysite.com/b-rev.php?id=1

Bye!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby php-punk » Wed May 14, 2003 11:10 am

rite, well were getting somewhere now:

the
b-rev.php?id=1 is now working but everything else from that point onwards is included within the link:

http://mysite.com/b-rev.php?id=1>1st</a></td></tr><tr><td> Posted

n e ideas?
php-punk
New php-forum User
New php-forum User
 
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk

Postby Joan Garnet » Wed May 14, 2003 3:22 pm

A couple of things:
celpadding should be cellpadding

Then there is a syntaxis error ( difficult to find :) )
The fix:
Code: Select all
echo "<a href=\"http://www.mysite.com/b-rev.php?id=3".$row["id"]."\">".$row["title"]."</a></font></td>";


Anyway, I would do this:

Code: Select all
echo "<a href='http://www.mysite.com/b-rev.php?id=3".$row["id"]."'>".$row["title"]."</a></font></td>";

so it is easier when you read it.

Bye!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby php-punk » Thu May 15, 2003 12:55 am

thanx for that!!! i'll give it a try on me server l8rs!!! (coz im at col atm and lycos is crap for speed and PHP!! lol)


Cheers!!
php-punk
New php-forum User
New php-forum User
 
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk

Postby php-punk » Thu May 15, 2003 10:42 am

right well i know got another question...lol

now i've got ID=VALUE

how do i get the other php script to have id equal the same value:

i got this so far..

Code: Select all

 <?PHP

$c = mysql_connect(localhost,"","") or die ("Sorry unable to connect to the database at point 1".mysql_error());

$db = mysql_select_db(stu,$c) or die("Sorry unable to connect to the database at point 1.5".mysql_error());

$query = "SELECT * FROM news WHERE id=''";

$result = mysql_query($query) or die("Sorry unable to connect to the database at point 2".mysql_error());

//then follows the rest of the script for it to be outputed !!

?>
php-punk
New php-forum User
New php-forum User
 
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk

Postby Joan Garnet » Thu May 15, 2003 4:46 pm

I don't think I understood you....
if you want the other Id value, just create a var that would contain taht value.

Inside the while statement of the first query put this:
$my_ID = $row['Id'];

So you can use it later on.
Did you mean that??

Bye!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

still not working!!

Postby php-punk » Sat May 17, 2003 11:38 am

rite, what i need is that when for example the link:

http://www.mysite.com/show.php?id=1 is clicked i need to know how i would be able ot use the variable ID in a SQL query in the WHILE section:

Code: Select all
//i need the id from the POST to be available in this statement
$query = "SELECT * FROM news WHERE id=$id";


i have this code but i dont know how to get teh variable available, i ahev tried many things such as $_POST[id] and that didn't work.

Code: Select all

<?PHP

//conecting
$c = mysql_connect(localhost,"","") or die ("Sorry unable to connect to the database at point 1".mysql_error());

//selecting DB
$db = mysql_select_db(stu,$c) or die("Sorry unable to connect to the database at point 1.5".mysql_error());

//setting query
$query = "SELECT * FROM news WHERE id=$id";

//running query
$result = mysql_query($query) or die("Sorry unable to connect to the database at point 2".mysql_error());


echo("<font color=\"#000000\" face=\"Geneva, Arial, Helvetica, san-serif\"><h1>Current Reviews</h1></font>");


//displaying returned results
while ($row = mysql_fetch_array($result))
{
   echo(" ");
   echo("<table cellpadding=\"1\" cellspacing=\"1\">");
      echo("<tr>");
         echo("<td> Posted By".$row["user"]."<i>Posted on".$row["date"]."</i></td>");
      echo("</tr>");
   echo("</table>");
}
   
   
   mysql_free_result($result);
?>
php-punk
New php-forum User
New php-forum User
 
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk

Postby Joan Garnet » Mon May 19, 2003 4:20 am

Well,
does this help ?


Code: Select all
while ( $row = mysql_fetch_array ( $result ) )
{
   echo " ";
   echo "<table cellpadding='1' cellspacing='1'><tr>";
   echo "<td> Posted By: " . $row["user"] . " <i>Posted on: " . $row["date"] . "</i></td>";
   echo"</tr></table>";
   
   echo "<a href='page.php?my_ID='" . $row["Id"] . ">pass the Id via GET</a>"; //this link will pass the Id via GET as $_GET ['my_ID']
   $ID_array[] = $row ["Id"]; //this is an array with all values just in case you want them in this script but out of the query
}

   mysql_free_result ( $result );
   
   echo "<PRE>";
   print_r ( $ID_array ); //this is the array's shape
   echo "</PRE>";


Bye!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

well.!!!

Postby php-punk » Tue May 20, 2003 10:20 am

sorted!!! :D!! thanx alot, i know have a reviews apge were users can pic a review from a list generated fromt the DB! shame lycos dont support cmd lines!!!

its crap!

n e ways thnx!!!!
php-punk
New php-forum User
New php-forum User
 
Posts: 60
Joined: Sun Feb 02, 2003 2:10 am
Location: Leeds, Uk


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.