PDA

View Full Version : Links, Forms, and Chips?


Deacon Frost
02-06-2008, 04:07 AM
Well, (nice forums first off, I'll prolly be very active here), I need to make a form that works off an image that is drawn from a variable that is pulled from a value in a mysql database.

So for instance...

if I connect to my database

and select the lolid

and give it to the variable $lolid

and then I have a link like:

http://www.example.com/images/ .jpg

and I wanted to put $lolid as the jpg file so it would open like so:

http://www.example.com/images/$lolid.jpg

how would I do that?

Now I want to put that in a form so A) the form is a picture using the lolid from the database and another preset link. B) Randomly generated according to value lolapproved with variable $lolapproved set to it, and if it is set to 2 then it shows up to 30 of the highest $id autoincrement lolapproved on one page. Each will link to http://www.example.com/example.php and must use the GET action.


I dunno if all that made enough sense, but I just need pointed in the right direction. For instance, how to make the form. I know how to do the database stuff, but just how to make the form work, where the images and the variables in the links, etc.


THX in advance.

StupidRalph
02-06-2008, 06:43 AM
Don't cross post. This should have never been posted here.

There are several ways to assign field values to variables.

mysql_result() (http://www.php.net/mysql_result) will probably be your best bet...

In addition you should check out this link (http://www.php.net/mysql).

And finally check this link out: http://hudzilla.org/phpwiki/index.php?title=Main_Page



$sql = 'SELECT * FROM `table`;

$q = mysql_query($sql) or die('mysql_error()' . 'SQL: ' . $sql'); //run query with error checking

while ($r = mysql_fetch_assoc($q)) {

echo $r['col1'] , $r['col2'] , $r['col3'] ; //$r is an associative array with the column value as the key. Notice I am using a while block. I'm just showing several different ways of doing it. I don't know your level of experience.
}



Here is one way...

$sql =
"SELECT `col1`,`col2`,`col3`,`col4 `
FROM `tbl_table`
WHERE
`col1` = 'some_value'";

$q = mysql_query($sql) or die('mysql_error()' . 'SQL: ' . $sql'); //run query with error checking

list($col1,$col2,$col3,$col4) = mysql_fetch_row($q) //assign the values to variables using the list()

Deacon Frost
02-06-2008, 08:05 AM
Thanks! However, that answers the other post, not this one. They are different ;). This one is about PHP, the other one is about MySQL. :).

That does answer a question, so thank you a lot.

Now how do I insert variables into a link, and how do I make an image form in php to where it uses the link with a variable in it?

StupidRalph
02-06-2008, 08:46 AM
My last posts answers both questions. Since you know how to store the database value in a variable now...you simply echo out the url.


//all of 3 these achieve the same result
echo "http://www.example.com/images/$lolid.jpg"; //with double quotes it will print the value of $lolid.
echo "http://www.example.com/images/" , $lolid , ".jpg"; //passes echo three parameters
echo "http://www.example.com/images/" . $lolid . ".jpg"; //concatenates the string

Deacon Frost
02-06-2008, 08:54 AM
Alright man! Much thanks! Now I can get dirty XD!

Again thanks, both questions answered


both of my titles with "chips" can be closed in PHP and MySQL or whatever you mods do :P!

StupidRalph
02-06-2008, 09:04 AM
Glad to hear it...I'm actually more aware during the daytime hours..its 4am here now so I'm winding down. But you can usually get most of your questions here. Its a really good community.

Deacon Frost
02-06-2008, 08:01 PM
I'm positive I'm doing something wrong cause

mysql_error()SQL: SELECT 'filmid','language','rating','synopsis','name' FROM 'theater' WHERE 'id'='1'


include("/home/stage/public_html/css/inc/theaterconn.php");

$sql =
"SELECT `filmid`,`language`,`rating`,`synopsis`,`name`
FROM `theater`
WHERE `id`=`1`";

$q = mysql_query($sql) or die('mysql_error()' . 'SQL: ' . $sql);
//run query with error checking

list($filmid,$language,$rating,$synopsis,$name) = mysql_fetch_row($q)
//assign the values to variables using the list()

angst
02-06-2008, 08:13 PM
check all field names and your data base name, make sure that the case is correct.

also I'm not sure why your doing the code this way, but theres allot of stuff here that you don't need. for example, the include path only needs to be relative to the scripts thats including it, you don't need an absolute path, also u don't need all those `````` in your sql statement,

also, why are you using list() to get the values from the query?
try mysql_fetch_assoc() instead.


include("css/inc/theaterconn.php");

$result = mysql_query("SELECT filmid,language,rating,synopsis,name FROM theater WHERE id=1") or die('mysql_error()' . 'Error: ' . mysql_errno() );
$row = mysql_fetch_assoc($result);

echo $row['filmid'];

Deacon Frost
02-06-2008, 08:20 PM
I need to have each column assigned a variable according to what the id is. Like we solved ^^^

angst
02-06-2008, 08:25 PM
umm,, yah...lol..
which is the same thing, only my code is much more neat and tidy and not all n00bed up.

Deacon Frost
02-06-2008, 08:28 PM
Ok, but, how do I assign different variables to each using what you gave me? It works, it just gives me teh filmid...

(I am incredibly new to what I'm trying to do, so please help ;))



EDIT: Nvm, I got the variables assigned, but now I have some other issues! Thanks!


Another Edit: I love you.

angst
02-06-2008, 08:33 PM
lol.. good work! ;)