php – Only the information of the first record appears

I’m working on a project that I would like to get an answer as soon as possible.

Problem: I have a project I’m doing. In this project, there will be events to buy tickets. The index will show all the records of the SQL database. When the event is clicked, only the information of the selected project will appear. However, this is where the problem lies. When I click on an event in the Index, it goes to the individual page of the product, but on that page, only the information of the first record always appears. Even if I click on another event in the index, the information from the first record will always appear on the individual page. (Example: The id 4 and 5 appear in the index. However, when I click on event 5, the information of id 4 will always appear on the page “eventoindividual.php”. I would like your best attention to solve the problem.

index.php

<?php
session_start();
    require('config.php');

if(!$con){
    header('location:erro.php');
} 

$sql=sprintf("SELECT * FROM eventos ORDER BY id DESC LIMIT 8");
$res=mysqli_query($con,$sql);
    

?>
<!DOCTYPE html>
<html>
<head>
    <link rel="shortcut icon" href="logotipoicon.png" />
    <!-- ==========================
        Meta Tags 
    =========================== -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- ==========================
        Title 
    =========================== -->
    <title>shop</title>
        
    <!-- ==========================
        Fonts 
    =========================== -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,200,200italic,300,300italic,400italic,600,600italic,700,700italic,900,900italic&amp;subset=latin,latin-ext" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,900,800" rel="stylesheet" type="text/css">

    <!-- ==========================
        CSS 
    =========================== -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
    <link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/dragtable.css" rel="stylesheet" type="text/css">
    <link href="assets/css/owl.carousel.css" rel="stylesheet" type="text/css">
    <link href="assets/css/animate.css" rel="stylesheet" type="text/css">
    <link href="assets/css/color-switcher.css" rel="stylesheet" type="text/css">
    <link href="assets/css/custom.css" rel="stylesheet" type="text/css">
    <link href="assets/css/color/red.css" id="main-color" rel="stylesheet" type="text/css">
    
    <!-- ==========================
        JS 
    =========================== -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    
</head>
<body>
    
    <!-- ==========================
        SCROLL TOP - START 
    =========================== -->
    <div id="scrolltop" class="hidden-xs"><i class="fa fa-angle-up"></i></div>
    <!-- ==========================
        SCROLL TOP - END 
    =========================== -->
    
    <!-- ==========================
        COLOR SWITCHER - START 
    =========================== -->
    
    <!-- ==========================
        COLOR SWITCHER - END 
    =========================== -->
    
    <div id="page-wrapper"> <!-- PAGE - START -->
    
    <!-- ==========================
        HEADER - START 
    =========================== -->
    <div class="top-header hidden-xs hidden">
        <div class="container">
            <div class="row">
                <div class="col-sm-5">
                    <ul class="list-inline contacts">
                        <li><i class="fa fa-envelope"></i> shop@mail.com</li>
                        <li><i class="fa fa-phone"></i> +1111111111</li>
                    </ul>
                </div>
                <div class="col-sm-7 text-right">
                    <ul class="list-inline links">
                        <li><a href="my-account.html">Minha Conta</a></li>
                        <li><a href="checkout.html">Checkout</a></li>
                        <li><a href="wishlist.html">Lista de Desejos</a></li>
                        <li><a href="compare.html">Comparar</a></li>
                        <li><a href="signin.html">Logout</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
        
    <header class="navbar navbar-transparent navbar-fixed-top">
        <div class="container" style="width: 50%;">
            <div class="navbar-header">
                <a href="index.php" class="navbar-brand"> <img src="logotipo.png"> </a>
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <i class="fa fa-bars"></i> </button>
            </div>
                
               <!-- <div class="teatroarte"><img src="opcoes/teatroarte.png"></div>
                    <div class="musicafestivais"><img src="opcoes/musicafestivais.png"></div>
                        <div class="familia"><img src="opcoes/familia.png"></div>
                            <div class="quatro"><img src="opcoes/desportoaventura.png"></div> -->
                
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                    </li>
                   
                    <li class="dropdown navbar-cart hidden-xs">
                        <a href="carrinho.php" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="300" data-close-others="true"><i class="fa fa-shopping-cart"></i></a>
                        <ul class="dropdown-menu">
                            
                        
                            <li>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <a href="carrinho.php" class="btn btn-primary btn-block">Ver carrinho</a>
                                    </div>
                                    <div class="col-sm-6">
                                        <a href="checkout.html" class="btn btn-primary btn-block">Finalizar</a>
                                    </div>
                                </div>
                            </li>
                            <!-- CART ITEM - END -->
                            
                        </ul>
                    </li>
                    <li class="dropdown navbar-search hidden-xs">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-search"></i></a>
                        <ul class="dropdown-menu">
                            <li>
                                <form>
                                    <div class="input-group input-group-lg">
                                        <input type="text" class="form-control" placeholder="Pesquisar...">
                                        <span class="input-group-btn">
                                            <button class="btn btn-primary" type="button">Pesquisar</button>
                                        </span>
                                    </div>
                                </form>
                            </li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="signin.php" class="fa fa-user" data-toggle="dropdown" data-hover="dropdown" data-delay="300" data-close-others="true"></a>
                        <ul class="dropdown-menu">
                            <li><a href="signin.php">Iniciar Sessão</a></li>
                            <li><a href="signup.php">Criar Conta</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
            </header>
    <!-- ==========================
        HEADER - END 
    =========================== -->  
           
    <!-- ==========================
        JUMBOTRON - START 
    =========================== -->
    <section class="content jumbotron jumbotron-full-height">
        <div id="homepage-2-carousel" class="nav-inside">
            
            <div class="item slide-1">
                <div class="slide-mask"></div>
                <div class="slide-body">
                </div>
            </div>
            <div class="item slide-2">
                <div class="slide-mask"></div>
                <div class="slide-body">
                </div>
            </div>
            <div class="item slide-3">
                <div class="slide-mask"></div>
                <div class="slide-body">
                </div>
            </div>
            <div class="item slide-4">
                <div class="slide-mask"></div>
                <div class="slide-body">
                </div>
            </div>
            <div class="item slide-5">
                <div class="slide-mask"></div>
                <div class="slide-body">
                </div>
            </div>
            <div class="item slide-6">
                <div class="slide-mask"></div>
                <div class="slide-body">
                </div>
            </div>
        </div>
    </section>
    <!-- ==========================
        JUMBOTRON - END 
    =========================== --> 
                
            </div>
    
    <!-- ==========================
        RECENT BLOG POSTS - START 
    =========================== -->

    <section class="content recent-blog-posts">
        <div class="container">
            <div class="section-title">
                <br>
                <h2 id="ultimasnovidades">ÚLTIMAS NOVIDADES</h2>
                <p>Encontra aqui as últimas novidades anunciadas.</p>
                <br>
                
            </div>
            <div class="row">
                
                <?php
                while($reg=mysqli_fetch_array($res)){
                    $sql_consulta=sprintf("select * from eventos where id=%d;",$reg['id']);
                    $res_consulta=mysqli_query($con,$sql_consulta);
                    $_SESSION['idevento'] = $reg['id'];
                   
                    $reg_consulta=mysqli_fetch_array($res_consulta);
                    $link='eventoindividual.php?id='.$reg_consulta['id'];
                    ?>
                    <div class="col-xs-6 col-sm-3">
                        <article class="post">
                            <a href="<?php echo $link; ?>"> <img src="<?php echo 'admin/documentos/'.$reg['nome_doc']; ?>" class="img-responsive" alt=""> </a>
                            <h3><a href="<?php echo $link; ?>"><?php echo $reg['nome']; ?></a></h3>
                            <span class="date"><?php echo $reg['data']; ?></span>
                        </article>
                    </div>
                    <?php
                }
                
                ?>
                
              
            </div>
        </div>
    </section>

eventoindividual.php

<?php
session_start();
require('config.php');
if(!$con){
    header('location:erro.php');
} 

$sql=sprintf("select * from eventos where id = '".$_SESSION['idevento']."'");
$res=mysqli_query($con,$sql);

?>

<!DOCTYPE html>
<html>
<head>
    <!-- ==========================
        Meta Tags 
    =========================== -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- ==========================
        Title 
    =========================== -->
    <title>shop</title>
        
    <!-- ==========================
        Fonts 
    =========================== -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,200,200italic,300,300italic,400italic,600,600italic,700,700italic,900,900italic&amp;subset=latin,latin-ext" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,900,800" rel="stylesheet" type="text/css">

    <!-- ==========================
        CSS 
    =========================== -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
    <link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/dragtable.css" rel="stylesheet" type="text/css">
    <link href="assets/css/owl.carousel.css" rel="stylesheet" type="text/css">
    <link href="assets/css/animate.css" rel="stylesheet" type="text/css">
    <link href="assets/css/color-switcher.css" rel="stylesheet" type="text/css">
    <link href="assets/css/custom.css" rel="stylesheet" type="text/css">
    <link href="assets/css/color/red.css" id="main-color" rel="stylesheet" type="text/css">
    
    <!-- ==========================
        JS 
    =========================== -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
    
</head>
<body>
    
    <!-- ==========================
        SCROLL TOP - START 
    =========================== -->
    <div id="scrolltop" class="hidden-xs"><i class="fa fa-angle-up"></i></div>
    <!-- ==========================
        SCROLL TOP - END 
    =========================== -->
    
    <!-- ==========================
        COLOR SWITCHER - START 
    =========================== -->
    
    <!-- ==========================
        COLOR SWITCHER - END 
    =========================== -->
    
    <div id="page-wrapper"> <!-- PAGE - START -->
    
    <!-- ==========================
        HEADER - START 
    =========================== -->
        <div class="top-header hidden-xs hidden">
        <div class="container">
            <div class="row">
                <div class="col-sm-5">
                    <ul class="list-inline contacts">
                        <li><i class="fa fa-envelope"></i> shop@mail.com</li>
                        <li><i class="fa fa-phone"></i> +111111111</li>
                    </ul>
                </div>
                <div class="col-sm-7 text-right">
                    <ul class="list-inline links">
                        <li><a href="my-account.html">Minha Conta</a></li>
                        <li><a href="checkout.html">Checkout</a></li>
                        <li><a href="wishlist.html">Lista de Desejos</a></li>
                        <li><a href="compare.html">Comparar</a></li>
                        <li><a href="signin.html">Logout</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
        
        <hr id="hrlogotipo">
    <!-- ==========================
        HEADER - END 
    =========================== --> 
    
    <!-- ==========================
        BREADCRUMB - START 
    =========================== -->
        <?php
                while($reg=mysqli_fetch_array($res)){
                    $sql_consulta=sprintf("select * from utilizadores where id=%s;",$reg['id']);
                    $res_consulta=mysqli_query($con,$sql_consulta);
                   
                    $reg_consulta=mysqli_fetch_array($res_consulta);
                    ?>
        
    <section class="breadcrumb-wrapper">
        <div class="container">
            <div class="row">
                <div class="col-xs-6">
                    <h2><?php echo $reg['tipoevento']; ?></h2>
                    <p><?php echo $reg['artista']; ?></p>
                </div>
                <div class="col-xs-6">
                    <ol class="breadcrumb">
                        <li><a href="index.php">Inicio</a></li>
                        <li class="active"><a href="eventoindividual.php"> <?php echo $reg['nome']; ?> </a></li>
                    </ol>
                </div>
            </div>
        </div>
    </section>
    <!-- ==========================
        BREADCRUMB - END 
    =========================== -->
    
    <!-- ==========================
        PRODUCTS - START 
    =========================== -->
        <section class="content products">
        <div class="container">
            <article class="product-item product-single">
                <div class="row">
                    
                    
                    <div class="col-xs-4">
                        <div class="product-carousel-wrapper">
                            <div>
                                <img src="<?php echo 'admin/documentos/'.$reg['nome_doc']; ?>" style="width: 370px;">
                                <br>
                                <br>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-8">
                        <div class="product-body">
                            <h2 style="color: #337ab7;"><b><?php echo $reg['nome']; ?></b></h2>
                            
                            <hr id="nomeevento">
    
                            <span class="price">
                                <ins><span class="amount"><b><?php echo $reg['preco']; ?></b></span></ins>
                            </span>
                            <hr>
                            <ul class="list-unstyled product-info">
                                <li style="color: #337ab7;"><span style="color: black;"><b>ID</b></span><?php echo $reg['id']; ?></li>
                                <li style="color: #337ab7;"><span style="color: black;"><b>Classificação</b></span><?php echo $reg['classificacao']; ?></li>
                                <li style="color: #337ab7;"><span style="color: black;"><b>Sessões</b></span><?php echo $reg['data']; ?> - <?php echo $reg['hora']; ?></li>
                                <li style="color: #337ab7;"><span style="color: black;"><b>Disponibilidade</b></span><?php echo $reg['estado']; ?></li>
                                <li style="color: #337ab7;"><span style="color: black;"><b>Promotor</b></span><?php echo $reg['promotor']; ?></li>
                            </ul>
                            
                            <hr>
                            
                            <h3 style="color: black"><b><?php echo $reg['1titulodescricao']; ?></b></h3>
                            <p><?php echo $reg['primeiradescricao']; ?> </p>
                            <div class="product-form clearfix">
                                <div class="row row-no-padding">
                                    
                                    <div class="col-md-3 col-sm-4">
                                        <div class="product-quantity clearfix">
                                            <a class="btn btn-default" id="qty-minus">-</a>
                                            <input type="text" class="form-control" id="qty" value="1">
                                            <a class="btn btn-default" id="qty-plus">+</a>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-3 col-sm-4">
                                        <div class="product-size">
                                            <form class="form-inline">
                                                <div class="form-group">
                                                    <label>Size:</label>
                                                </div>
                                                <div class="form-group">
                                                    <select class="form-control">
                                                        <option>XS</option>
                                                        <option>S</option>
                                                        <option selected="selected">M</option>
                                                        <option>L</option>
                                                        <option>XL</option>
                                                        <option>XXL</option>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-3 col-sm-4">
                                        <div class="product-color">
                                            <form class="form-inline">
                                                <div class="form-group">
                                                    <label>Color:</label>
                                                </div>
                                                <div class="form-group">
                                                    <select class="form-control">
                                                        <option selected="selected">Black</option>
                                                        <option>White</option>
                                                        <option>Red</option>
                                                        <option>Yellow</option>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-3 col-sm-12">
                                        <a href="" class="btn btn-primary add-to-cart"><i class="fa fa-shopping-cart"></i>Comprar</a>
                                    </div>
                                    
                                </div>
                            </div>
                            <ul class="list-inline product-links">
                                <li><a href="#"><i class="fa fa-heart"></i>Add to wishlist</a></li>
                                <li><a href="#"><i class="fa fa-exchange"></i>Compare</a></li>
                                <li><a href="#"><i class="fa fa-envelope"></i>Email to friend</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            
            <div class="tabs product-tabs">
                <ul class="nav nav-tabs" role="tablist">
                    <ul class="nav nav-tabs" role="tablist">
                    <li role="presentation" class="active"><a href="#description" role="tab" data-toggle="tab" aria-controls="description" aria-expanded="false">Descrição</a></li>
                    <li role="presentation" class=""><a href="#video" role="tab" data-toggle="tab" aria-controls="video" aria-expanded="false">Video de apresentação</a></li>
                </ul>
            
                </ul>
                <div class="tab-content">
                    <div role="tabpanel" class="tab-pane active in" id="description">
                        <h3><b><?php echo $reg['2titulodescricao']; ?></b></h3>
                        <p><?php echo $reg['segundadescricao']; ?> </p>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="reviews">
                    
                        <div class="comments">
        
                
                <?php
                
                }
                
                ?>
                
            
                    <div class="releated-products">
                        <h2>Eventos Relacionados</h2>
                        <div class="row grid" id="products">
                        
                    <!-- PRODUCT - START -->
                    <div class="col-sm-3 col-xs-6">
                        <article class="product-item">
                            <div class="row">
                                <div class="col-sm-3">
                                    
                                    <?php
                
                $sqli=sprintf("SELECT * FROM eventos ORDER BY id DESC LIMIT 8");
                $resu=mysqli_query($con,$sqli);
                mysqli_set_charset($con, 'UTF8');
                    
                while($regi=mysqli_fetch_array($resu)){
                    $sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
                    $resu_consulta=mysqli_query($con,$sqli_consulta);
                   
                    $regi_consulta=mysqli_fetch_array($resu_consulta);
                    $linkk='eventoindividual.php?id='.$regi_consulta['id'];
                    ?>
                                    
                                    <div class="product-overlay">
                                        <div class="product-mask"></div>
                                        <a href="single-product.html" class="product-permalink"></a>
                                        <img src="<?php echo 'admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
                                    </div>
                                </div>
                                <div class="col-sm-9">
                                    <div class="product-body">
                                        <h3><?php echo $regi['nome']; ?></h3>
                                        <span class="price">
                                            <ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
                                        </span>
                                        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut feugiat mauris eget magna egestas porta. Curabitur sagittis sagittis neque rutrum congue. Donec lobortis dui sagittis, ultrices nunc ornare, ultricies elit. Curabitur tristique felis pulvinar nibh porta. </p>
                                        <div class="buttons buttons-simple">
                                            <a href=""><i class="fa fa-exchange"></i></a>
                                            <a href=""><i class="fa fa-shopping-cart"></i></a>
                                            <a href=""><i class="fa fa-heart"></i></a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </article>
                    </div>
                    
                </div>
            </div>
            
                        <?php
                
                }
                
                ?>

        </div>

Leave a Comment