Results 1 to 6 of 6

Thread: Getting information from sql DB and display on Web Page

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting information from sql DB and display on Web Page

    Is there a way to get the number of results from fields in Database
    For instance if I have 4 fields say x1 x2 x3 and x4.
    x1 has 3 records
    x2 doesnt have any
    x3 has 10 records
    x4 20 records
    On the web page it would show
    x1 3
    x3 10
    x4 20
    note x2 doesnt have any so nothing is shown but if it did then it would be shown like the others.
    Also a row might have a record for a combination of x fields so the resulds would need to still be counted.

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    I'm not sure about your DB setup.

    something like this will result in counting all the records in the entire table

    Code:
    SELECT COUNT(*) FROM table;
    You might want to look more into the COUNT command for more info.
    Also, have a look at this to see if it's more of what you want.

    http://www.tizag.com/mysqlTutorial/mysqlcount.php

  3. #3
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This is the start I think but its not real pacific see it at p.htm

    PHP Code:
    $query "SELECT Attend_Round, COUNT(Monster_Truck) FROM Entry_Form GROUP BY Attend_Round"
         
    $result mysql_query($query) or die(mysql_error());

    // Print out result
    while($row mysql_fetch_array($result)){
        echo 
    $row['Attend_Round'] ." "$row['COUNT(Monster_Truck)'] ." items.";
        echo 
    "<br />";
    }
    ?> 
    I think I need something more like this but dont know how to make it work. the above probably needs more to it as you can see I have more than just Monster truck to look at for the echo.
    PHP Code:
    $result=mysql_query($query);

    $num=mysql_numrows($result);

    if (
    $num==0) {

    echo 
    "";
    }else{
    echo 
    "";
    }

    mysql_close();

    $i=0;
    while (
    $i $num) {

    $Attend_Round=mysql_result($result,$i,"Attend_Round");
    $Eighth_Scale_Buggy=mysql_result($result,$i,"Eighth_Scale_Buggy");
    $Eighth_Scale_Sportsman=mysql_result($result,$i,"Eighth_Scale_Sportsman");
    $Arena_Truck=mysql_result($result,$i,"Arena_Truck");
    $Monster_Truck=mysql_result($result,$i,"Monster_Truck");
    $Stadium_Truck=mysql_result($result,$i,"Stadium_Truck");
    echo 
    "<b>$Name<br>$Eighth_Scale_Buggy<br>$Eighth_Scale_Sportsman<br>$Arena_Truck<br>$Monster_Truck<br>$Stadium_Truck<hr>";

    $i++;


  4. #4
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Can someone please help me

  5. #5
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    I don't have much experience with SQL but I know you can do it with a (probably less resource-efficient) piece of code like this:

    PHP Code:
    $query "SELECT * FROM Entry_Form GROUP BY Attend_Round"
    $result mysql_query($query) or die(mysql_error());

    // Print out result
    $x 1;
    while(
    $row mysql_fetch_array($result)){
        print 
    "<b>Entry " $x "</b><br />";
        
    $x++;
        foreach(
    $row as $key => $value) {
            
    printf("%s %s<br />",$value,$key);
        }
        print 
    "<hr />";
    }
    ?> 

  6. #6
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to clarify my objective better

    Take a look at this first to see what Im trying to do. "keep in mind im trying to figure out how to do this so the top of page may be chaging from time to time with my attemps, but the bottom is what my goal is to achieve which is not php or anything simplely a display of what I want to happen.
    Here what I would like to use, but insted of display each entry individgualy just display the Attend_Round ie wichita rc raceway, track2. once then count how many times each of these Eighth_Scale_Buggy, Eighth_Scale_Sportsman, Arena_Truck, Monster_Truck, Stadium_Truck accour for the value of Attend_Round.
    Im sure count is the right thing to do, but have tried many differant things with no succes. I dont know where to put it in the $query= 'SELECT line i guess.

    PHP Code:
    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");
    mysql_query($query);
    $query'SELECT Attend_Round, Eighth_Scale_Buggy, Eighth_Scale_Sportsman, Arena_Truck, Monster_Truck, Stadium_Truck FROM Entry_Form';

    $result=mysql_query($query);

    $num=mysql_numrows($result);

    if (
    $num==0) {

    echo 
    "";
    }else{
    echo 
    "";
    }

    mysql_close();

    $i=0;
    while (
    $i $num) {

    $Attend_Round=mysql_result($result,$i,"Attend_Round");
    $Eighth_Scale_Buggy=mysql_result($result,$i,"Eighth_Scale_Buggy");
    $Eighth_Scale_Sportsman=mysql_result($result,$i,"Eighth_Scale_Sportsman");
    $Arena_Truck=mysql_result($result,$i,"Arena_Truck");
    $Monster_Truck=mysql_result($result,$i,"Monster_Truck");
    $Stadium_Truck=mysql_result($result,$i,"Stadium_Truck");

    echo 
    "<B>$Attend_Round</b><BR>";

    if (
    $Eighth_Scale_Buggy != ""){
    echo  
    "$Eighth_Scale_Buggy<BR>";
    }
    if (
    $Eighth_Scale_Sportsman != ""){
    echo  
    "$Eighth_Scale_Sportsman<BR>";
    }
    if (
    $Arena_Truck != ""){
    echo  
    "$Arena_Truck<BR>";
    }
    if (
    $Monster_Truck != ""){
    echo  
    "$Monster_Truck<BR>";
    }
    if (
    $Stadium_Truck != ""){
    echo  
    "$Stadium_Truck<BR>";
    }

    echo 
    "<hr>";

    $i++;
    }
    ?> 
    Last edited by big-dog1965; 01-02-2008 at 10:07 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
  •