Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Mysql data to html tables question

    If this is an inappropriate request please let me know. Have searched forums and googled for tutorials, but not a php coder and don't really have time to learn it all so asking the experts. Need some simple code to accomplish the following:

    Have mysql dbase (islandsbikesandb2) with one table (catalog).
    6 fields in row:
    id_num ( int, primary, auto increment)
    mfg (varchar)
    model (varchar)
    type (varchar)
    desc (varchar)
    photo_path (varchar)

    dbase and table created, Have php script to upload data via form for local admin . All works.

    Need script to display contents of table(catalog) as follows:

    Call: show_catalog.php? type=sometype mfg=somemfg

    Return:

    <html>
    <body>


    <table>
    <tr>
    <td>
    for each record where type=sometype and mfg=somemfg , echo from (table=catalog)
    (mfg) <br>
    <img src=(photo_path) width=150px height=100> <br>
    (model)
    </td>
    </tr>
    </table>


    Display: Table = 4 cells wide 4 rows high per page.As many pages as required to include all records in call.
    Truncate if less than 16 matching records
    No choice as to items per page for user.


    A nice extra to avoid me having to shame myself by asking again:
    In <td> above a link such as ><a href = show_item.php?><img src=(photo_path) width=150px height=100></a>
    (eg; <a href=show_item.php? (variables to show record fields mfg, photo_path,desc for specific record))

    Addition info:

    Am using "includes" config.php and opendb.php in working scripts

    configdb:

    <?php
    $dbhost = 'host_ip_address';
    $dbuser = user_name';
    $dbpass = 'pswd';
    $dbname = 'db_name';
    ?>

    opendb.php:

    <?php
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    mysql_select_db($dbname);
    ?>

    As you can see, I know just enough PHP to be dangerous..... TIA for your help, and a few pointers to some GOOD tutorials or code snippets would be much appreciated.

    CaptDavid
    Savannah GA
    USA

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    A few functions to look into, one which you have likely used already
    mysql_query()
    This is the one that will do most of the work, examples in manual
    mysql_fetch_array()

    The hardest part would be building your query. Can you show us your query statement so far?
    Last edited by _Aerospace_Eng_; 02-28-2008 at 08:06 AM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Feb 2008
    Location
    Cork- Ireland
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    just change the query as required and enmbed in file

    PHP Code:

    <php?

    $result mysql_query("SELECT id_num, mfg, model,type, desc, photo_path   FROM catalog'");

    if (!
    $result) {
        die(
    "Query to show fields from table failed");
    }

    $fields_num mysql_num_fields($result);

      print 
    "</tr>";

    echo 
    "<table border='0'><tr>";
    // printing table headers

    for($i=0$i<$fields_num$i++)
    {
        
    $field mysql_fetch_field($result);
      
      
    // option to print mysql field names as headers

        
    echo "<td>{$field->name}</td>";
    }
    echo 
    "</tr>\n";
    // printing table rows
    while($row mysql_fetch_row($result))

    {
        echo 
    "<tr>";

        foreach(
    $row as $cell)
            echo 
    "<td>$cell</td>";

        echo 
    "</tr>\n";
    }

    mysql_free_result($result);

    ?> 
    Wow - I did'nt know that !!!


  •  

    Posting Permissions

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