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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Split mysql query into columns:do the job with php or better Css?

    So all my doubt is in the title

    have a child page who display's many details info about a determinated item on mysql db.
    On the display of the child page have a table:

    |Images|description|Date|

    so at the request it the column have 4 images they will display in only one colum..is it possible to "limit" that colum for example in only 2 items:
    | images | Description | Date |
    img1|img2
    img3|img4
    tried some snippets of code but im not there
    Would a rather use Css for that kind of job, more simple or PHP to "limit" my colums?

    PHP Code:
    <?php
    $page_title 
    'Article Detail';
    //include ('includes/header.html');
    require_once ('mysqli_connect.php');
    if ( (isset(
    $_GET['art_nome'])) ) { $id $_GET['art_nome'];
    } else { 
    // No valid ID, kill the script.
        
    echo '<p class="error">This page has been accessed in error.</p>'
        exit();
    }
         
    $q="SELECT artigos.art_nome, artigos.art_desc, artigos.art_price, categorias.cat_nome, imagens.* FROM 
         imagens INNER JOIN artigos ON imagens.art_nome = artigos.art_nome 
                         INNER JOIN categorias ON imagens.cat_nome = categorias.cat_nome WHERE imagens.art_nome = '$id'"
    ;
     
    $r = @mysqli_query ($dbc$q)
     or die(
    "Error: ".mysqli_error($dbc));
    $num_rows=mysqli_num_rows($r); 
     echo 
    "<table align=\"center\" table border=\"1\" cellspacing=\"0\">
      <tr><td></td>
              <td>Image</td>
              <td>Date</td>
              <td>Item Number</td>"
    ;
    while (
    $row mysqli_fetch_array ($rMYSQLI_ASSOC)) {
    echo 
    "<tr><td>$row[imagem_nome]</td><td>$row[imagem_data]</td><td>$row[imagem_id]</td></tr>";

    }
    echo 
    "</table>";
    echo 
    $num_rows;
    ?>
    appreciate your comments

  • #2
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ok tables in php are not the best answer to positioning queries at display, rather use Css.
    Someone have some samples or tutorials PHP css to look up what i'm searching?
    thank u

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Use CSS for sure, don't use multiple MySQL queries.

    If you put each image in a div tag an "left float" each div, they'll stack left to right, top to bottom.

  • #4
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    tried this:
    Columns with css and mysql query
    how u could put <div> tags among ure php code?
    could u feed me a sample?
    thank u

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I use echo() for that.

    PHP Code:
    echo "<div>"

  • #6
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    tried like that
    Code:
    echo "<Div id=\"gallerycontainer\"<href=\"../images/{$row['imagem_nome']}'
                               border='0'>
                <img src='../images/{$row['imagem_nome']}' border='0'
                  width='100' height='80'></a>";
    Last edited by Cyber_type; 05-07-2009 at 07:41 PM.

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    It has to be valid HTML though.. your code is going to produce

    Code:
    <Div id="gallerycontainer"<href="../images/filename.jpg' border='0'>
    <img src='../images/filename.jpg' border='0' width='100' height='80'></a>
    That's not valid.

  • #8
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    restarted from zero to make some another tries

    PHP Code:
    <?php
    require_once ('mysqli_connect.php');
     
    $q="SELECT * FROM imagens";
     
    $result = @mysqli_query ($dbc$q)
     or die(
    "Error: ".mysqli_error($dbc));
    while (
    $rows mysqli_fetch_array($result))
    {
    extract ($rows);
    $image_nome $rows['imagem_nome'];
     
    $image_data $rows['imagem_data']; 
      
    $image_id $rows['imagem_id']; 
                }
    ?>
    <html>
    <head>
           <link rel="stylesheet" href="includes/css1.css" type="text/css" media="screen" />
         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
         <title>Details</title>
     </head>
     <body>
     <div id="container">
     <img src="<?php echo "../images/$rows['imagem_nome']" border='0'>
    </
    div>
    </
    body>
    </
    html>
    but i get a "parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING" at line 22.

  • #9
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Ok, I think we're getting a little beyond the original issue and crossing over into PHP 101 here.

  • #10
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    gotta take a look onto ure link. thanks
    tried that
    Code:
    <img src="<?php echo "../images/$rows['imagem_nome']" ?>" border='0'>
    nope not better always the same error.

  • #11
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <img src="<?php echo "../images/$rows[imagem_nome]" ?>" border='0'>
    Voila, it works
    ive replaced the code between the DIV tag for
    Code:
    <img src="<?php echo "a href='../images/{$rows['imagem_nome']}'
                               border='0'>
                <img src='../images/{$rows['imagem_nome']}' border='0'
                  width='100' height='80'></a>" ?>
    works, no error on executing the script but doesn't display correctly the image (only u know a little graphic....) and the request has a while loop who normally displays all the images on the db.....
    What must i change on my code?
    thank u

  • #12
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    find some code on CodingForums it works

    PHP Code:
    <?php
    $connection 
    mysql_connect("localhost" "user" "pass") or die ("Can't connect to MySQL");
    $db mysql_select_db("com" $connection) or die ("Can't select database.");

    $cols 2;
    $size = (80/$cols) - 5;
    $result mysql_query("SELECT * FROM imagens order by imagem_id desc") or die (mysql_error());
    if (
    mysql_num_rows($result) > 0){
        echo <<<CSS
    <style>
    html, body, div{padding:0px; margin:0px;}
    .img {padding:10px; hover img: border: 5px solid blue; margin: 0 5px 5px 0;hover:background-color: transparent;}
    .cell {width: 
    {$size}%; float:left;}
    .thumbnail
    {
    clear:both; 
    overflow:hidden;
    margin: 100px;
    position: absolute;
    width: 30%;
    }
    </style>
    <div class="thumbnail">    
    CSS;
        while (
    $t mysql_fetch_object($result)) {
            echo <<<HTML
    <div class="cell">
    <a href=../images/
    {$t->imagem_nome} border='0'>
    <img src='../images/
    {$t->imagem_nome}' width='100' height='80' border='0'></a>
    </div>        
    HTML;
    }
    echo 
    "</div><!--close results div--!>";
    } else {
        echo 
    "no results";
    }

    ?>
    now how can i reuse the query $connection to display some other information from the table imagens?
    |img|img|img_date
    |img|img|img_desc
    must i make another connectioms to the table or can i reuse the query?

  • #13
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    $connection isn't a query, it's a connection. The query is $result. And yes you can use $result just like any other array.

  • #14
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    u're right $result , may i have a little sample from ure's? or a tutorial?
    in any cases outside the loop correct?

  • #15
    New Coder
    Join Date
    Jun 2007
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts
    tried this
    Code:
    $row2= mysql_fetch_array($query);
    			$article_name= $row2['art_nome'];
    			echo $article_name;
    while($row = mysql_fetch_array($query))
    {
         $image_name = $row['imagem_nome'];
        	echo $image_name;
     }
     $row1= mysql_fetch_array($query);
    			$image_date = $row1['imagem_data'];
    			echo $movie_date;
    without the css for the moment
    that will be another nightmare
    so the result: have the field $article_name, the while() loop $image_name is also ok, it works but the field $image_name doesn't appearwhy?
    any ideas or advices?
    i know my code a bit poor maybe i must to know more about classes or some another code upgrade?
    thank u
    Last edited by Cyber_type; 05-23-2009 at 11:03 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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