For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > November 2004 > How to produce a $mysql_query_sentence?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to produce a $mysql_query_sentence?
Claus Ladekjær Wilson

2004-11-01, 3:56 pm

I have worked to have a very generic code so that I could modify it to be
used with any database.
My query-sentence I now looks like this:

$mysql_query_sentence=
$sql_work[$sql_work_sql][$sql_taeller].$sql_data[$sql_num][$sql_taeller++]
..$sql_work[$sql_work_sql][$sql_taeller].$sql_data[$sql_num][$sql_taeller++]
..$sql_work[$sql_work_sql][$sql_taeller].$sql_data[$sql_num][$sql_taeller++]
..$sql_work[$sql_work_sql][$sql_taeller].$sql_data[$sql_num][$sql_taeller++]
;

How could I write some code to have this produced automatically?

Hilarion

2004-11-01, 8:56 pm

Try some loops (eg. "foreach", "for", "while").
Egzample with "for":

<?php

$mysql_query_sentence = '';
foreach( $sql_taeller = 0; $sql_taeller < count( $sql_data[$sql_num] ); $sql_taeller++ )
{
$mysql_query_sentence .= $sql_work[$sql_work_sql][$sql_taeller].$sql_data[$sql_num][$sql_taeller];
}

?>

Hilarion

PS.: Wouldn't it be easier to store SQL queries for each DB as whole? Your method makes
the code really hard to read.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com