[thelist] using URL's to update mysql db

Mark Mckee lists at soddengecko.com
Tue Oct 31 08:18:07 CST 2006


hi Mattias

thanks for your reply. your code offering is easier to read and probably 
quicker. i will change the code over.

the list of themes is generated from the themes folder, the database 
only holds the title of the current theme. 1 table with 1 row. i am 
still learning and so far have only worked out my templating system this 
way, i am open to suggestions on how to make it quicker and smaller.

basically i call the db row like so

$sql = 'SELECT * FROM theme;';
$result = mysql_query($sql) or die('');
while ($row = mysql_fetch_assoc($result)){
$themefolder = $row['theme'];
}
include "themes/$themefolder/header.php";
}

and it all seems to work fine. again, open to any suggestions on this.

i have a few other simple (to some) problems with securing the admin 
area but thats for another post

thank you again for the reply

mark m...


Mattias Thorslund wrote:
> I don't see that anyone has replied to this yet. So, just some small
> pointers/opinions:
> 
> 1. It seems you will need to decide whether to use MySQL as the source
> for the list of themes or not. Ultimately, the "master" list of
> available themes seems to be whatever is available in the themes folder,
> so if you're using a the SQL table to keep the list of themes (better
> performance? alternate names?), this must be synced with the folder
> contents - preferably in some automated way. From what you have written,
> it seems that MySQL isn't necessary here.
> 
> 2. This line is pretty confusing, since the third part is not a
> comparison but an assignment:
> 
> if ($file != "." && $file != ".." && $file="<a href=\"$file\">$file</a>\n"){
>    //...
> }
> 
> 
> How about this? Easier to read, don't you think?
> 
> if ($file != "." && $file != ".."){
>    $file="<a href=\"$file\">$file</a>\n";
>    //...
> }
> 
> As for the "making the url update mysql" part, a tutorial on SQL would
> tell you how. SELECT/INSERT/UPDATE/DELETE, or by using MySQL's
> proprietary REPLACE command. But again, I doubt you'll need any of it.
> 
> /Mattias
> 
> 
> Mark Mckee wrote:
>> hi all
>>
>> I am writing a small templating instruction and so far have everything
>> working neatly. I have a few queries I would like to run by you guys as
>> I'm having trouble finding the answer, I have looked in the usual places
>> and found nothing that helps.
>>
>> each template sits in its own folder i.e.. themes/template1 or
>> themes/default. I am using a mysql row to define the template, which is
>> set at default to begin with and is outputted like so
>>
>> -----------------------------------------------
>> function gl_header()
>> {
>>
>> $sql = 'SELECT * FROM theme;';
>> $result = mysql_query($sql) or die('');
>> while ($row = mysql_fetch_assoc($result)){
>>
>> $filename = "themes/".$row['theme']."";
>>
>> if (file_exists($filename)) {
>> include "themes/".$row['theme']."/header.php";
>> } else {
>> include "themes/default/header.php";
>> }
>> }
>> }
>> -----------------------------------------------
>>
>> this is where I'm getting slightly stuck. I have a small script that
>> will read the folder names from the template directory and output the
>> folder name as a url
>>
>> -----------------------------------------------
>> function gl_themechooser()
>> {
>> $handle=opendir('./themes');
>>
>> while ($file = readdir($handle)) {
>> if ($file != "." && $file != ".." && $file="<a href=\"$file\">$file</a>\n")
>> {
>> echo ".$file.";
>> }
>> }
>> closedir($handle);
>> }
>> -----------------------------------------------
>>
>> I would like to know how to make this url update the mysql row when
>> clicked. I tried outputting them into a drop down box but a separate box
>> was created for each folder in the template directory and ii was unable
>> to solve this. any pointers on that would be great.
>>
>> Thanks in advance
>>
>> Mark M...
>>   
> 




More information about the thelist mailing list