English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,
i need to recreate the function requete()
function requete($var,$var2)
i imagine the return is an array but i can not found how to recreate the function

$formule=array("M1", "P1", "P2", "P3", "P4", "P5", "P6",

foreach ($formule as $key=>$value) {
${'req_'.$value}=requete("SELE... tarif FROM tarifs WHERE age=".$age." and genre=".$rens_pers['sexe']." and regime=".$rens_pers['regime'].... and formule='$value'","req_ tarif");

${'req_'.$value} is an querys array?
how can i return it and use it?

anyone have an idea?
thank you for your help

2007-09-12 05:34:10 · 3 answers · asked by locin4r 1 in Computers & Internet Programming & Design

i finally found the aswer:

function requete($sql_requete, $message) {
$resultat=mysql_query($sql_requete) or die ('


'.mysql_error().' avec
'.$sql_requete.'
Message : '.$message.'
');
$i=0;
//echo $sql_requete."
";
while($data = mysql_fetch_array($resultat))
{
$y=0;
foreach($data as $key => $value)
{
if($y%2) $tableau[$i][$key]=$value;
$y++;
}
$i++;
}
return $tableau;

but when i send my array tho the function who use the fonction requete();
i can not pass values of my array

i able to send source code by mail cause he is huge the i dont want put everything here.

thanks for your help
}

2007-09-12 10:26:01 · update #1

3 answers

Sound and looks strange. You should better show more info or code. If I understand, You can simply return $array in function and then access this as a normal array.

2007-09-12 07:24:05 · answer #1 · answered by kolibrizas 3 · 0 0

Totally wrong way to use a database. File access is slow, difficult to manage, and has been known to bring down a whole web server under load. Since php has every possible facility you might need with mysql, use the full potential. The correct way to do this is to use an int() primary key auto_increment for all the tables, except any which may regularly be used and cleared. So create a table for your tags using the ID and a field named, say, tags varchar(45) unique key Then a link table with NO primary key, and fields of tagid against whatever else id you need. Simply add a tag.id and the id for wherever you want the tags to be. There is nothing wrong with joins, the work very well, you can actually use a 3 way join to read this information direct, but it is often more versatile to use (purely eg): $page_res =mysql_query("Select * from pagetable"); while($page_rec = mysql_fetch_array($page_res)){ // run either a join select query on the link table and the tags table, or //a simple query on the link and another on the tags. //so for a record set from the final query of $tag_rec : $tag_list .=",".$tag_rec[tags]; //This builds a string containing all the related tags. This way the same tags can be used on any part of the site, or left unattached to some pages.

2016-05-17 22:12:58 · answer #2 · answered by ? 3 · 0 0

I am an expert in PhP and MySQL, but I must confess I have no idea what you are trying to do!...
Your form «${'req_'.$value}» is what I do not understand.

«("SELECT tarif FROM tarifs WHERE age=".$age." and genre=".$rens_pers['sexe']." and regime=".$rens_pers['regime'].... and formule='$value'","req_ tarif");»
is a query that will return a "ressource".
I usually code:
$query = "Select ... "
then place the query:
$list = mysql_query($query) or die("Query failed : " . mysql_error());

$list is a ressource: you must TAKE it:
$lst = mysql_fetch_array($list)

Then, read $lst[0], 1, 2, 3 or whatever.

Remember: 5 steps:
1. Define your query: $query = "Select ... "
2. Place your query: $list=mysql_query($query) ...
3. FETCH your query: $lst = mysql_fetch_array($list)
4. Use the results: echo $lst[x];
DON't forget to release you ressource:
5. mysql_free_result($list);

2007-09-12 06:02:32 · answer #3 · answered by just "JR" 7 · 0 0

fedest.com, questions and answers