John Davidson

html - Send static data from one php to another

0 comments
Message:


I have a php file results.php with a grid of different items (each item is a row from the result of a certain query). When I click an item it takes me to another php file details.php where I want to show more details in the new page about the specific item I clicked.


function showAsItem($row) {
$defaultValue = $row[1];
$itemClassname="item";
$titleClassname="title";
$imageClassname="image";
$infoClassname="infolist";
$link="details.php";
$target="_top";
$img="https://barcelonando.com/es/wp-content/uploads/2012/12/barceloneta.jpg";
$alt="Imagen de $row";

echo '<div class="'.$itemClassname.'">';
echo '<div class="' .$titleClassname. '">';
echo '<a href="'.$link.'" target="' .$target. '">' .ucfirst($row[0]). '</a>';
echo '</div>';
echo '<div class="' .$imageClassname. '">';
echo '<a href="' .$link. '" target="' .$target. '">';
echo '<img src="' .$img. '" alt="' .$alt. '"/>';
echo '</a>';
echo '</div>';
echo '<div class="' .$infoClassname. '">';
echo '<ul>';
echo '<li> Poblaci&oacute;n: ' .$row[1]. '</li>';
echo '<li> Esperanza de vida: ' .$defaultValue. '</li>';
echo '<li> Inmigrantes: ' .$defaultValue. '</li>';
echo '<li> Transportes: ' .$defaultValue. '</li>';
echo '<li> Accidentes: ' .$defaultValue. '</li>';
echo '</ul>';
echo '</div>';
echo '</div>';
}

I only know how to send info from one webpage to another when it is an input type, but in this case I want to send the item static info (I just need to send the name of the item I clicked). Any idea about how to do it?



My Answer:
"item";
echo "
";
echo "Item $defaultValue";
echo "
";
}

// In results.php
$query = "SELECT * FROM items";
$result = mysqli_query($conn, $query);

while ($row = mysqli_fetch_array($result)) {
showAsItem($row);
}

// In details.php
$id = $_GET['id'];
$query = "SELECT * FROM items WHERE id = $id";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_array($result);

echo "Details for item $id:";
echo "
";
print_r($row);
echo "
";

Rate this post

3 of 5 based on 4507 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us