Gallery PHP Mysql
Results 1 to 3 of 3

Thread: Gallery PHP Mysql

  1. #1
    Junior Member
    Join Date
    Jun 2017
    Posts
    1

    Cool Gallery PHP Mysql

    M**Php / mysql gallery issues
    I have made a gallery in php. It receives from an index page an "inname" parameter. The gallery every time it passes from page does not manage to send 2 parameters at the same time and in all inombre. Unparameter of the database "idtext"
    Please tell me the mistakes**

    enter code here

    index.php

    Lista de Acontecimientos<Br /> <?php $conexion = mysqli_connect("localhost", "root", "") or trigger_error(mysql_error(),E_USER_ERROR); mysqli_select_db($conexion,"db674013292"); $consulta="Select * from textos where clase=1 "; $result=mysqli_query($conexion,$consulta); ?> <?php while($fila=mysqli_fetch_row($result)){ echo "<a href=\"H.php?inombre='".$fila['0']."'\">".$fila['1']."</a><br>"; } ?>

    Gallery.php




    <?php
    $inombre=$_GET['inombre'];

    $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
    $objDB = mysql_select_db("db674013292");

    $strSQL = "SELECT * FROM galeriadecidiendo where idtexto =$inombre ";

    $objQuery = mysql_query($strSQL);
    $Num_Rows = mysql_num_rows($objQuery);

    $Per_Page = 8; // Per Page

    @$Page = $_GET["Page"];
    if(!@$_GET["Page"])
    {
    $Page=1;
    }

    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;

    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
    $Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
    $Num_Pages =($Num_Rows/$Per_Page) ;
    }

    else
    {
    $Num_Pages =($Num_Rows/$Per_Page)+1;
    $Num_Pages = (int)$Num_Pages;
    }

    $strSQL .=" order by idgaleriatexto ASC LIMIT $Page_Start , $Per_Page";
    $objQuery = mysql_query($strSQL);


    echo"<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
    $intRows = 0;
    while($objResult = mysql_fetch_array($objQuery))
    {
    echo "<td>";
    $intRows++;
    ?>
    <img with="150" height="150" src="<?=$objResult["url"]; ?>"><br>
    <?PHP
    echo"</td>";
    if(($intRows)%4==0)
    {
    echo"</tr>";
    }
    }
    echo"</tr></table>";
    ?>
    <br>
    <span class="paguinas">Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :</span>


    <?PHP
    if($Prev_Page)
    {
    echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'><< Back</a> ";
    }

    for($i=1; $i<=$Num_Pages; $i++){
    if($i != $Page)
    {
    echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'>$i</a> ]";
    }
    else
    {
    echo "<b> $i </b>";
    }
    }
    if($Page!=$Num_Pages)
    {
    echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page$Prev_Page&$inombre=idtexto'>Next>></a> ";
    }
    ?>


    <?PHP
    mysql_close($objConnect);
    ?>




    </body>
    </html>

  2. #2
    Senior Member cluelessPHP's Avatar
    Join Date
    Apr 2015
    Location
    Scotland
    Posts
    356
    Hi a few things, you seem to be mixing mysql_ with mysqli_ , mysql_ is deprecated now always use either

    PDO
    http://php.net/manual/en/pdo.connections.php

    or

    mysqli_
    http://php.net/manual/en/function.mysqli-connect.php

    Your query's were a little wrong too you can find out more at
    http://php.net/manual/en/mysqli.query.php

    You can learn more about mysqli_num_rows here
    http://php.net/manual/en/mysqli-result.num-rows.php

    As an aside, indentation is important you can read more about it here
    http://mrbool.com/importance-of-code-indentation/29079

    There were a few other things but I guess that's enough for now, it's a good start don't give up
    Once you had a good excuse, you opened the door to bad excuses ― Terry Pratchett, Thud
    Blog

    Six month project

  3. #3
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,765
    Here's the code within this forum's [php]...[/php] tags. It was, in fact, indented, but the OP did not use the forum tags to display nicely.

    PHP Code:
        Lista de Acontecimientos<Br />  <?php $conexion mysqli_connect("localhost""root""") or trigger_error(mysql_error(),E_USER_ERROR); mysqli_select_db($conexion,"db674013292"); $consulta="Select * from textos where clase=1 "$result=mysqli_query($conexion,$consulta); ?>  <?php  while($fila=mysqli_fetch_row($result)){ echo "<a href=\"H.php?inombre='".$fila['0']."'\">".$fila['1']."</a><br>";    }  ?>
     
    Gallery.php




    <?php
    $inombre
    =$_GET['inombre'];

            
    $objConnect =  mysql_connect("localhost","root","") or die(mysql_error());
            
    $objDB =  mysql_select_db("db674013292");
            
            
    $strSQL "SELECT * FROM galeriadecidiendo where idtexto =$inombre ";

            
    $objQuery mysql_query($strSQL);
            
    $Num_Rows mysql_num_rows($objQuery);

            
    $Per_Page 8;   // Per Page

            
    @$Page $_GET["Page"];
            if(!@
    $_GET["Page"])
            {
                
    $Page=1;
            }

            
    $Prev_Page $Page-1;
            
    $Next_Page $Page+1;

            
    $Page_Start = (($Per_Page*$Page)-$Per_Page);
            if(
    $Num_Rows<=$Per_Page)
            {
                
    $Num_Pages =1;
            }
            else if((
    $Num_Rows $Per_Page)==0)
            {
                
    $Num_Pages =($Num_Rows/$Per_Page) ;
            }

            else
            {
                
    $Num_Pages =($Num_Rows/$Per_Page)+1;
                
    $Num_Pages = (int)$Num_Pages;
            }

            
    $strSQL .=" order  by idgaleriatexto ASC LIMIT $Page_Start , $Per_Page";
            
    $objQuery  mysql_query($strSQL);


            echo
    "<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
            
    $intRows 0;
            while(
    $objResult mysql_fetch_array($objQuery))
            {
                echo 
    "<td>"
                
    $intRows++;
        
    ?>
    <img with="150" height="150" src="<?=$objResult["url"]; ?>"><br>                 
        <?PHP
                
    echo"</td>";
                if((
    $intRows)%4==0)
                {
                    echo
    "</tr>";
                }
            }
            echo
    "</tr></table>";
        
    ?>
            <br>
        <span class="paguinas">Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :</span>
            
            
                    <?PHP
            
    if($Prev_Page)
            {
                echo 
    " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'><< Back</a> ";
            }

            for(
    $i=1$i<=$Num_Pages$i++){
                if(
    $i != $Page)
                {
                    echo 
    "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&$inombre=idtexto'>$i</a> ]";
                }
                else
                {
                    echo 
    "<b> $i </b>";
                }
            }
            if(
    $Page!=$Num_Pages)
            {
                echo 
    " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page$Prev_Page&$inombre=idtexto'>Next>></a> ";
            }
            
    ?>


        <?PHP
    mysql_close
    ($objConnect);
    ?> 




    </body>
    </html>
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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