Jump to content

Recommended Posts

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

 

 

 

 

 

 

    enter code here

 

 

 

    $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> ";

    }`enter code here`

    ?>

    

    

    <?PHP

    mysql_close($objConnect);

    ?> 

    

    

    

    

    </body>

    </html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/304100-php-mysql-gallery-issues/
Share on other sites

I have corrected the code a little.
I'm asking for help
 
 
<?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>

I have already changed the code to mysqli but the problem persists since I wrongly send the parameter inname every time that page step please as I send it

 

 

 

 
 
 
<?php
$inombre=$_GET['inombre'];
 
$objConnect =  mysqli_connect("localhost","root","") or die(mysql_error());
$objDB =  mysqli_select_db($objConnect,"db674013292");
 
$strSQL = "SELECT * FROM galeriadecidiendo where idtexto =$inombre ";
 
$objQuery = mysqli_query($objConnect,$strSQL);
$Num_Rows = mysqli_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  = mysqli_query($objConnect,$strSQL);
 
 
echo"<table border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
$intRows = 0;
while($objResult = mysqli_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
mysqli_close($objConnect);
?> 
 
 
 
 
</body>
</html>

in addition to fixing the implementation details for the database statements, your code needs to do/not do some things -

 

1) don't use the @ error suppressor. if you have input data that is optional, use isset() and some logic to detect if the variable is present and also set up a default value if it is not. do this for the $_GET['inombre'] and $_GET['Page'] variables.

 

2) you need to decide what your code is going to do when there isn't a $_GET['inombre'] input. it should either - 1) output a message and don't run any of the code and queries, or 2) set up a default value and run the code and queries.

 

3) don't select all the rows of data from your table to get the total number of rows. use SELECT COUNT(*) ... to get the total number of rows. this query and your main data retrieval query need the same WHERE clause (and any JOIN conditions, if you are joining tables.) to supply the same WHERE clause for both queries, form the WHERE clause in a php variable, then just use the php variable when you build each sql query statement.

 

4) the pagination links need to be built with both the page number and any existing $_GET parameters, which will include the $_GET['inombre'] value. the easiest way of doing this is to use the http_build_query() function. see this post for an example - https://forums.phpfreaks.com/topic/301197-getting-error-catchable-fatal-error/?do=findComment&comment=1533115

 

please use the forum's


bbcode tags (the edit form's <> button) around code when posting it in the forum.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.