Professional Web Applications Themes

looping query - PHP Development

hello how to make a loop to query db 5 times. i need some general sketch. thx konrad...

  1. #1

    Default looping query

    hello
    how to make a loop to query db 5 times. i need some general sketch.

    thx

    konrad




    Konrad Guest

  2. #2

    Default Re: looping query

    Konrad Tuszkowski wrote: 

    for($i=0;$i<5;$i++) {
    $reulst=mysql_query("Select * from Table LIMIT 1");
    }

    a loop that query a database 5 times, no data displayed. Could be a bit more
    useful to be more specific what you want to do.

    More info about mysql_query can be found at:
    http://www.php.net/manual/en/function.mysql-query.php



    //Aho
    J.O. Guest

  3. Moderated Post

    Default Re: looping query

    Removed by Administrator
    JDS Guest
    Moderated Post

  4. #4

    Default Re: looping query

    thank u.
    i just needed some direction, not a direct solution. no fun then :):):)
    but thanks :):):):)
    if ur interested i am struggling with some issues in my scrtipt (see "form
    problem" post by me)
    "J.O. Aho" <net> wrote in message
    news:net... 
    >
    > for($i=0;$i<5;$i++) {
    > $reulst=mysql_query("Select * from Table LIMIT 1");
    > }
    >
    > a loop that query a database 5 times, no data displayed. Could be a bit[/ref]
    more 


    Konrad Guest

  5. #5

    Default Re: looping query

    Konrad Tuszkowski wrote: 

    /* Create an array and insert values that has been set */
    if(isset($A) && !empty($A)) {
    /* As $A is the first possible value, the create the array*/
    $looparray=$array($A);
    }
    if(isset($B) && !empty($B)) {
    /* There is an $B value */
    if(isset($looparray)) {
    /* If the array has already been set, insert this value*/
    array_push($looparray,$B);
    } else {
    /* if the array hasn't been created, make it now */
    $looparray=$array($B);
    }
    }
    if(isset($C) && !empty($C)) {
    if(isset($looparray)) {
    array_push($looparray,$C);
    } else {
    $looparray=$array($C);
    }
    }
    if(isset($D) && !empty($D)) {
    if(isset($looparray)) {
    array_push($looparray,$D);
    } else {
    $looparray=$array($D);
    }
    }
    if(isset($E) && !empty($E)) {
    if(isset($looparray)) {
    array_push($looparray,$E);
    } else {
    $looparray=$array($E);
    }
    }
    /* We echo how many variables has been set */
    echo"<br>".count($looparray)."<br>\n";
    /* We check that there has been values set, or else we won't try to fetch
    anything from the database */
    if(isset($looparray)) {
    /* We loop through the array and fetch each value from database*/
    for($i=0;$i<count($looparray);$i++) {
    $query ="SELECT matom,nazwa FROM chem WHERE symb LIKE
    '".$looparray[$i]."' LIMIT 1";
    $result = mysql_query ($query) or die ("Zapytanie zakonczone
    niepowodzeniem");
    $wiersz = mysql_fetch_array($result);
    $a=$wiersz["matom"];
    $b=$wiersz["nazwa"];
    $tab_b[]=$b;
    $tab_a[]=$a;
    echo "Masa molowa <b>$b"."u</b> wynosi $a<br>\n";
    }
    } else {
    /* No values set, we need to give an error message */
    echo "brak danych<br>\n";
    }

    This would give you all five, if all five values are set, if less values are
    set, then just those times are a value from the database fetched. The code is
    untested and I have just got up from bed, so it may not work directly but may
    need a bit tweaking, but I think you get a pretty good idea from it what to do.


    //Aho
    J.O. Guest

  6. #6

    Default Re: looping query

    thx, and i did it like this:
    if ($_POST['A']) { $tablica[0]=$_POST['A']; }
    if ($_POST['u']) { $wartosci[0]=$_POST['u']; }
    if ($_POST['B']) { $tablica[1]=$_POST['B']; }
    if ($_POST['w']) { $wartosci[1]=$_POST['w']; }
    if ($_POST['C']) { $tablica[2]=$_POST['C']; }
    if ($_POST['x']) { $wartosci[2]=$_POST['x']; }
    if ($_POST['D']) { $tablica[3]=$_POST['D']; }
    if ($_POST['y']) { $wartosci[3]=$_POST['y']; }
    if ($_POST['E']) { $tablica[4]=$_POST['E']; }
    if ($_POST['z']) { $wartosci[4]=$_POST['z']; }


    $wiersze=count($tablica);
    for($i=0;$i<$wiersze;$i++) {
    $result=mysql_query("SELECT nazwa,matom FROM chem WHERE symb =
    '$tablica[$i]' ");
    $wiersz = mysql_fetch_array($result);
    echo "Masa molowa <b>".$wiersz['nazwa']."u</b> wynosi
    ".$wiersz['matom']."<br>";

    }

    it works as i want for now,
    because i am a totally newbe, so i prefer simple 9but sometimes not smart
    enouh) solutions. will try ur if mine stucks somewhere.

    thx again
    konrad


    Konrad Guest

  7. #7

    Default Re: looping query


    Użytkownik "Konrad Tuszkowski" <pl> napisał w wiadomości
    news:dcgq1b$fo7$onet.pl... 

    Is there any reasons that You ask on alt.comp.lang.php, alt.php? hmmm....
    don/t know (like) Polish?

    Grzesiek


    Witold Guest

Similar Threads

  1. Index Looping in a Query ...
    By istock1 in forum Coldfusion Database Access
    Replies: 4
    Last Post: January 15th, 02:54 PM
  2. Looping over a Query with locking
    By Trygve in forum Coldfusion - Advanced Techniques
    Replies: 7
    Last Post: October 5th, 11:48 AM
  3. Looping an update query
    By Yannovich in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: September 22nd, 07:51 AM
  4. looping over a query object
    By fu-meng in forum Coldfusion - Advanced Techniques
    Replies: 6
    Last Post: March 24th, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139