Page 1 of 1

Filling out the header data from mySQL

Posted: Fri Apr 24, 2009 6:32 am
by MYSTERYouse
Hello all,

I would like to implement dynamicaly generated headers for a webpage and I am stucked on the mySQL query, better said I don't understand the definition of one variable.

For the start:
each php page starts with code similar to this:

Code: Select all

<?php
$sID='x-y-z';
?>
The x-y-z are actually related to the sections of a webpage (for instance x-parameter is for the 1st subpage level http://site.com/level1)
By using this definition it was possible to use following code:

Code: Select all

<img src="/img/imgname_<?=$sID[0]?>_<?=$sID[1]?>_<?=$sID[2]?>.jpg"
This way I dont have to change the links of each picture, the code can stay the same for each page.

_________________

To my problem:

I would like to use the $sID='x-y-z' variable content in an mySQL query to get data out of the database for specific pages based on its $sID value in this way:

Code: Select all

$query = 'SELECT title, description FROM meta WHERE siteID = $sID';
$results = mysql_query($query);
while ($line = mysql_fetch_assoc($results)) {
        $title = $line['title'];
        $description = $line['description'];
}
I know that the part of the query after where is wrong, could you help me out with it?
I coulnt find any info on the variable definition with the dashed value, when I want to output it to screen using echo, I just get output: "Array"


Anyone from you have an idea how this kind of variable is working?

EDIT>>> I forgot to add one line which I found in one of the included php files:

Code: Select all

$sID    =   explode ("-", $sID);

Re: Filling out the header data from mySQL

Posted: Sun Apr 26, 2009 7:25 am
by josephchoufani
just change
$sID = explode ("-", $sID);
to for example:

Code: Select all

$sID_a =  explode ("-", $sID);
and use

Code: Select all

<img src="/img/imgname_<?=$sID_a[0]?>_<?=$sID_a[1]?>_<?=$sID_a[2]?>.jpg">

Re: Filling out the header data from mySQL

Posted: Sun Apr 26, 2009 7:45 am
by MYSTERYouse
Thx for reply first,

I digged around a bit and found a easier workaround without needing to change all the picture links

Code: Select all

 
...
$webID = implode("-", $sID);
$query = "SELECT title, description, siteid FROM meta where siteid ='$webID'";
...
 
Basically used a reverse function to get the sID back into one piece instead of an array so it can be used now in the query.

I would say its resolved now :D