Bootstrap Cards Filter PHP/AJAX Problems - php

I have a page of a website which has bootstrap cards on. The cards are generated dynamically, but I wanted to add a filter section. I am trying to use AJAX to acheive this, I have got to a point where when you select a checkbox it triggers the loader gif but then that loader gif doesn't disapear. Through my hours of debugging I can see that its the page that the AJAX call is calling that is the problem, but I just can't see what the issue is and I am not getting errors or anything in the console.
If anyone has any ideas I would really appreciate it, I have pasted my code below, also I am aware my sql queries are currently open to injection, just want to get it to work first.
<body>
<?php include("PHP/header.php"); ?>
<div class="container-fluid">
<div class="container" style="margin-top: 2%; text-align: center;">
<h1>Title goes here</h1>
Some tetx
<br/>
<br/>
<br/>
Filter Reviews:
<ul class="list-group">
<?php
$search = $conn->prepare("SELECT DISTINCT reviewcat FROM review_db ORDER BY reviewcat");
$search->execute();
while ($row = $search->fetch(PDO::FETCH_ASSOC)) {
?>
<li class="list-group-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input product_check" value="<?=$row['reviewcat'];?>" id="reviewcat"> <?=$row['reviewcat']; ?>
</label>
</div>
</li>
<?php } ?>
</ul>
</div>
<br/><br/>
<div class="row-fluid ">
<h5 class="text-center" id="textChange"> All Products </h5>
<hr>
<div class="text-center">
<img src="Images/loader.gif" id="loader" width="100" style="display: none">
</div>
<div id="result" class="card-deck card_group_style pt-4" >
<?php
$res_data = $conn->prepare("SELECT * FROM review_db");
$res_data->execute();
?>
<?php while ($row = $res_data->fetch(PDO::FETCH_ASSOC)) {// Important line !!! Check summary get row on array .. ?>
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/<?php echo $row['reviewimage1'];?>" alt="<?php echo $row['reviewtitle'];?>" >
<div class="card-body">
<h5 class="card-title"><?php echo $row['reviewtitle'];?></h5>
<p class="card-text"><?php echo $row['reviewsynop'];?></p>
<a href="Reviews/review-content.php?id=<?php echo $row['id'];?>&reviewtitle=<?php echo $row['reviewtitle'];?>" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: <?php
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;?></small>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include("PHP/footer.php"); ?>
</div>
</body>
<?php include("PHP/js.php"); ?>
<script>
$(document).ready(function(){
$('#link-review,#link-footer-review').addClass('active');
});
</script>
<script type="text/javascript">
$(document).ready(function(){
function get_filter_text(text_id){
var filterData = [];
$('#'+text_id+':checked').each(function(){
filterData.push($(this).val());
});
return filterData;
}
$(".product_check").click(function(){
$("#loader").show();
var action = 'data';
var reviewcat = get_filter_text('reviewcat');
$.ajax({
method:'POST',
url:'reviewaction.php',
data:{action:action,reviewcat:reviewcat},
success:function(response){
$("#result").html(response);
$("#loader").hide();
$("#textChange").text("Filtered Reviews");
}
});
});
});
</script>
</html>
reviewaction.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
include_once $_SERVER['DOCUMENT_ROOT'] . '/Private/db.php';
// $stmt = $conn->prepare("SELECT * FROM blogdata ORDER BY blogsub DESC");
// $stmt->execute();
?>
<?php
if(isset($_POST['action'])){
$sql = "SELECT * FROM review_db WHERE reviewcat !=''";
$revsearch = $conn->prepare($sql);
$revsearch->execute();
$output='';
if($revsearch->num_rows>0){
while ($row = $revsearch->fetch(PDO::FETCH_ASSOC)) {
$output .= '
<div class="col-sm-6 col-lg-3 py-2">
<div class="card mb-4">
<img class="card-img-top card-images " src="Images/Reviews/'. echo $row['reviewimage1'];.'" alt="'. echo $row['reviewtitle'];.'" >
<div class="card-body">
<h5 class="card-title">'. echo $row['reviewtitle'];.'</h5>
<p class="card-text">'. echo $row['reviewsynop'];.'</p>
<a href="Reviews/review-content.php?id='. echo $row['id'];.'&reviewtitle='. echo $row['reviewtitle'];.'" class="btn btn-primary my-4" >Read More</a>
<div class="card-footer" style="padding: 1%;">
<small class="text-muted">Submitted: '.
$my_date = $row['reviewsub'];
$date = DATE("d/m/Y",strtotime($my_date));
echo $date;.'</small>
</div>
</div>
</div>
</div>
';
}
else{
$output = "<h3>No Reviews Found!</h3>";
}
echo $output;
}
?>

I have actually found something in the server error log, I was stupidly only use dev tools on firefox, but have found that in the reviewaction.php script I had left semicolons in and had also missed a closing bracket. There are still some other problems, which I can fix, just couldn't work out why it wasn't firing.

Related

Fetch data from mysql by checking radio button

i have few models of products and when i click on each model to show me his variants, like on image from below
Here is what i made in html :
<div class="owl-carousel owl-theme no-pb slide-arrow-2" data-
dots="false" data-nav="true" data-items="4" data-lg-items="3"
data-md-items="2" data-sm-items="2" data-margin="30" data-
autoplay="false">
<?php
$qua = "SELECT * FROM produse WHERE categorie = '$id' ORDER BY pozitie";
$qla = mysqli_query($conn, $qua);
while($rova = mysqli_fetch_assoc($qla)){?>
<?php
$id_paletar = $rova['id'];
$sql2=mysqli_query($conn,"SELECT * FROM pret_produse WHERE produs_id='$id_paletar'");
$pret2=mysqli_fetch_array($sql2);
?>
<div class="item">
<div class="product-item">
<div class="product-img">
<img class="img-fluid" src="cms/produse/<?=$rova['poza'];?>" alt="">
<div class="product-overlay">
<ul class="list-unstyled">
</ul>
</div>
</div>
<div class="product-btn ifix">
<div class="btn btn-theme btn-block btn-new" ><span style="font-size: 15px;"><?=$rova['titlu'];?></span>
<div>
<label class="containere">
<input type="radio" name="produse" id="paletar_pret" class="palt" value="<?=$rova['id'];?>">
<p class="checkmark"></span>
</label>
</div>
</div>
</div>
</div>
</div>
<?php }?>
</div>
Here is my jquery:
$(document).ready(function(){
$('.palt').change(function() {
if(this.checked) {
var check= $(this).val();
alert(check);
$.ajax({
url: 'cere_cotatie.php',
type: 'POST',
data: {check:check},
success: function(data){
$('.fetch').append(data);
}
});
}
});
And here is my php file which i use on ajax to call:
<?php
if($_POST)
{
include('config.php');
echo $check = $_POST['check'];
$s = "SELECT * FROM variante WHERE id_var='$check'";
$q = mysqli_query($conn, $s);
while ($r = mysqli_fetch_assoc($q)) {?>
<div class="item" style="width:220px;">
<div class="product-item">
<div class="product-img">
<img class="img-fluid" src="cms/variante/<?=$r['poza'];?>" alt="">
<div class="product-overlay">
<ul class="list-unstyled">
</ul>
</div>
</div>
<div class="product-btn ifix">
<div class="btn btn-theme btn-block btn-new" ><span style="font-size: 15px;"> <?=$r['denumire'];?></span>
<div>
<label class="containere">
<input type="checkbox">
<p class="checkmark"></span>
</label>
</div>
</div>
</div>
</div>
</div>
<?php }?>
<?php }
?>
My problem is like this if i check first box to display me variants of what i checked but my code is doing this way, if i check first box is loading data and after that if i check another box results from first box need to dissapear and to be only what i check.
EDIT: in that print screen you can see the problem.
I think you should add below code
$('.palt').change(function(e) {
e.preventDefault();
});
and remove alert(check);
Hope it work for you.

how to display 3 columns dynamic data from database using bootstrap 4

Following is my code I am displaying details as 3 columns per row using Bootstrap class row.
I tried like changing div and some condition
<div class="container">
<?php
if($lclResult->rowCount() > 0){
while($row = $lclResult->fetch(PDO::FETCH_ASSOC)) {
# code...
$lclUserName = $row['us_business_name'];
$lclImage1 = $row['us_image1'];
$lclCategory = $row['us_category'];
$lclArea = $row['us_area'];
?>
<div class="row">
<div class="col-sm-4">
<div class="card">
<img class="card-img-top " src="<?php echo $lclImage1 ?>" alt="Card image" style="width:100%; height: 158px;">
<div class="card-body">
<h4 class="card-title"><?php echo $lclUserName?></h4>
<p class="card-text" style="font-size: 25px;"><?php echo $lclCategory?></p>
<hr>
<i class="fa fa-map-marker" style="font-size: 23px;"><span> </span><?php echo $lclArea?></i>
<!-- See Profile -->
</div>
</div>
<?php
}
?>
</div>
<?php
} else {
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1> NO RESULT FOUND...</h1>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
I want to display 3 columns per row to display data. If anyone knows Please guide me with the above code.
Change your code like this
<div class="container">
<div class="row">
<?php
if($lclResult->rowCount() > 0){
while($row = $lclResult->fetch(PDO::FETCH_ASSOC)) {
# code...
$lclUserName = $row['us_business_name'];
$lclImage1 = $row['us_image1'];
$lclCategory = $row['us_category'];
$lclArea = $row['us_area'];
?>
<div class="col-sm-4">
<div class="card">
<img class="card-img-top " src="<?php echo $lclImage1 ?>" alt="Card image" style="width:100%; height: 158px;">
<div class="card-body">
<h4 class="card-title">
<?php echo $lclUserName?>
</h4>
<p class="card-text" style="font-size: 25px;">
<?php echo $lclCategory?>
</p>
<hr>
<i class="fa fa-map-marker" style="font-size: 23px;">
<span>
</span>
<?php echo $lclArea?>
</i>
<!-- See Profile -->
</div>
</div>
</div>
<?php
}
?>
<?php
} else {
?>
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1> NO RESULT FOUND...
</h1>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>

Create a session variable when user clicks a button inside a loop

I have a button inside a loop.
When the user clicks on the button I want to create a $_SESSION variable with the value of a variable inside the loop.
For example, the variable $id_puja is 767 at this loop item, when the user clicks on the button I want to create the session variable $_SESSION['clicked_puja'] = $row['id_puja'].
This is the button:
while{...
$id_puja = $row['id_puja'];
...
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
...
}
I
EDITED, full loop code:
<?php
$resultadopujas=0;
global $mysqli;
$loop = mysqli_query($mysqli, "SELECT * FROM tb_pujas
WHERE subasta_puja = '".$subasta."'")
or die (mysqli_error($mysqli));
$orden = 0;
$resultado = $loop ->num_rows;
if ($resultado == 0){
?> <div class="container">
<div class="jumbotron">
<div class="row">
<div class="col-md-6">
<p><?php echo $resultado."NO HAY PUJAS"?></p>
</div>
</div>
</div>
</div>
<?php
}
$numpuja=0;
while ($row = mysqli_fetch_array($loop))
{$numpuja = $numpuja+1;
$originalDate = $row['datetime_puja'];
$newDate = date("d-m-Y H:i:s",strtotime($originalDate))
?>
<div class="container">
<div class="jumbotron" style="background-color: white">
<div class="row">
<div class="col-md-2">
<img style="width: 80px;height: auto;align-self: " src="garantia.png">
</div>
<div class="col-md-2">
<img style="width: 80px;height: auto;align-self: " src="ok.png">
</div>
<div class="col-md-2">
<img style="width: 80px;height: auto;align-self: " src="extra.png">
</div>
<div class="col-md-2">
<p><strong>Dia/Hora puja: </strong><?php echo $newDate?></p>
</div>
<div class="col-md-2">
<p><strong>Precio puja: </strong><?php echo $row['precio_puja']." €"?></p>
</div>
<div class="col-md-2">
<p><?php echo "<strong>Puja núm:</strong> ".$numpuja?></p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p><?php echo "<strong>Comentarios:</strong> ".$row['comentarios_puja']?></p>
</div>
</div>
<div class="row">
<div class="col-md-4">
<img style="width: 100%;height: auto;align-self: " src="https://cribbeo.com/pujas/<?php echo $row['foto1']?>">
</div>
<div class="col-md-4">
<img style="width: 100%;height: auto;align-self: " src="https://cribbeo.com/pujas/<?php echo $row['foto2']?>">
</div>
<div class="col-md-4">
<img style="width: 100%;height: auto;align-self: " src="https://cribbeo.com/pujas/<?php echo $row['foto3']?>">
</div>
</div>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
<div class="col-md-4">
<script>
function myclick(){
alert (<?php echo $row['precio_puja']?>);
}
</script>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" id="boton" onclick="myclick()" data-target="#myModal">Open Modal</button>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
EDITED modal part
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Mensajes de la subasta <?php echo $referencia."VAR=".$_COOKIE['puja']?></h4>
</div>
<div class="modal-body" style="background-color:#486A86; color: white">
<div class="container">
<header class="header">
<h1>Chat</h1>
</header>
<main>
<img src="images/logohorizontal.png" alt="Cribbeo" width="200px">
<div class="userSettings">
<label for="userName">Usuario: <?php echo $_SESSION['usuario']?></label>
<input id="userName" type="hidden" placeholder="Username" maxlength="32" value=" <?php echo $_SESSION['usuario']?>">
</div>
<div class="chat">
<div id="chatOutput"></div>
<input id="chatInput" type="text" style="background-color:white; color: #486A86" placeholder="Escribe aquí el texto de tu mensaje" maxlength="128">
<button id="chatSend" style="background-color:#486A86; color: white">Enviar</button>
</div>
</main>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
And this is chat.js
$(document).ready(function() {
var chatInterval = 250; //refresh interval in ms
var $userName = $("#userName");
var $chatOutput = $("#chatOutput");
var $chatInput = $("#chatInput");
var $chatSend = $("#chatSend");
function sendMessage() {
var userNameString = $userName.val();
var chatInputString = $chatInput.val();
$.get("./write.php", {
username: userNameString,
text: chatInputString
});
$userName.val("");
retrieveMessages();
}
function retrieveMessages() {
$.get("./read.php", function(data) {
$chatOutput.html(data); //Paste content into chat output
});
}
$chatSend.click(function() {
sendMessage();
});
setInterval(function() {
retrieveMessages();
}, chatInterval);
});
Try this-
//START OF LOOP...
//Add data-var attribute to your button to store the value of the session variable to be picked up by jQuery.
<button type="button" class="btn btn-info btn-lg session-btn" data-toggle="modal" data-target="#myModal" data-var="<?php echo $id_puja;?>">Open Modal</button>
//END OF LOOP..
// jQuery CDN link
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script>
$('.session-btn').on('click', function(){
var session_var = $(this).data('var');
console.log(session_var); // prints the session variable value to the console.
$(document).ready(checkModal);
function checkModal() {
if($('#myModal').is(':visible')){
//if the modal is visible on the page
$.ajax({
url: 'read.php',
type: 'POST',
data: {session_var: session_var},
success: function(){
alert('success');
}
});
}
}
});
</script>
In read.php file
<?php
require("connect.php");
session_start():
//connect to db
$db = new mysqli($db_host,$db_user, $db_password, $db_name);
if ($db->connect_errno) {
//if the connection to the db failed
echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error;
}
if(isset($_POST['session_var'])){
$_SESSION['session_var'] = $_POST['session_var'];
echo $_SESSION['session_var'];
$query="SELECT * FROM chat WHERE id_puja ='".$_SESSION['session_var']."' ORDER BY id ASC";
//execute query
if ($db->real_query($query)) {
//If the query was successful
$res = $db->use_result();
while ($row = $res->fetch_assoc()) {
$username=$row["username"];
$text=$row["text"];
$time=date('G:i', strtotime($row["time"])); //outputs date as # #Hour#:#Minute#
echo "<p>$time | $username: $text</p>\n";
}
}else{
//If the query was NOT successful
echo "An error occured";
echo $db->errno;
}
} else {
echo 'variable is not posted!';
}
$db->close();
?>

how to give a if else here

i want to include a else statement after the completion of the block after the second if for category equal to helathcare ....now i want another else for finance but i am not getting where excatly to place that else
i have a confusion on where to keep the else for finance and 2 more categories
now whenever i try to place the one else at the last goes unrecable to its if statement i donno its very confusing as to where to place 2 more else if statments for 2 more categories
<?php
global $row2;
if(isset($_POST['category']))
{
if($_POST['category']== 'Healthcare')
{
$query = "select *from event where category = 'Healthcare';";
$result=mysqli_query($conn,$query)or die(mysqli_error($conn));
while($row2= mysqli_fetch_array($result))
{
?>
<div class="events events-full event-list">
<div class="container">
<div class="row">
<div class="col-md-9 col-sm-8">
<!--Blog Post Start-->
<div class="blog-post">
<div class="post-thumb">
<div class="link-wrap"> <i class="fa fa-search"></i> <i class="fa fa-link"></i> </div>
<img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
<div class="event-text">
<div class="event-counter"></div>
<h4> <?php echo($row2['title']); ?> </h4>
<p><?php echo($row2['descrption']); ?></p>
<p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
<p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
<a class="nd" href="">
<form action="eventdetail.php" method="post">
<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>
<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
</div>
</a> </div>
</div>
</form>
<!--Blog Post End-->
<?php }
}
}
else
{
global $row2;
$query = "select *from event;" ;
$result=mysqli_query($conn,$query)or die(mysqli_error($conn));
while($row2= mysqli_fetch_array($result))
{
?>
<div class="events events-full event-list">
<div class="container">
<div class="row">
<div class="col-md-9 col-sm-8">
<!--Blog Post Start-->
<div class="blog-post">
<div class="post-thumb">
<div class="link-wrap"> <i class="fa fa-search"></i> <i class="fa fa-link"></i> </div>
<img src="images/gallery/<?php echo $row2['event_image']?>" alt='user'></div>
<div class="event-text">
<div class="event-counter"></div>
<h4> <?php echo($row2['title']); ?> </h4>
<p><?php echo($row2['descrption']); ?></p>
<p><span class="glyphicon glyphicon-map-marker"><?php echo($row2['location']); ?></span></p>
<p><span class="glyphicon glyphicon-grain"><?php echo($row2['organizer']); ?></span></p>
<a class="nd" href="">
<form action="eventdetail.php" method="post">
<input type='hidden' value="<?php echo $row2['id']; ?>" name='id'/>
<button type="submit" class="btn btn-primary" name="detail" value=”detail”>Event Detail</button>
</div>
</a> </div>
</div>
</form>
<!--Blog Post End-->
<?php } } ?>
?>
You can't put multiple else blocks along with the if block. However, you can use multiple(as many as you want) elseif/else if blocks along with the if block, like this:
if($_POST['category'] == 'Healthcare'){
...
}elseif($_POST['category'] == 'Finance'){
...
}elseif($_POST['category'] == '...'){
...
}else{
...
}
Here's the reference: http://php.net/manual/en/control-structures.elseif.php
Part of your problem seems to be poor formatting. If you lined up your open and close tags for your if statements I think you would be able to see this better. Having said that, you can add any elseif/if clauses for the category if where I marked below:
<!--Blog Post End-->
<?php
} // closes while loop
} else{ } // closes healthcare if, add extra else here
} // closes POST if
else
{

How can i create permanently accessible urls from database entries?

I am trying to make a mirror of the this site for my own country, but I am having a hard time comperehending how to create new urls from my database entries.
For example as on the site I linked, it has and id/name to identify that exacty site, i want to achieve the same to make seperate questions shareable.
My current code is only created to test with 1 question on localhost url.
Here's a little snippet of what I've currently got:
<?php
$id = 1;
$result = performQuery("SELECT * FROM dilemmas WHERE id = ".$id);
while($row = mysqli_fetch_array($result)){
$blue_question = utf8_encode($row['blue_question']);
$blue_votes = utf8_encode($row['blue_votes']);
$red_question = utf8_encode($row['red_question']);
$red_votes = utf8_encode($row['red_votes']);
}
?>
<div class="answer-peek">
<div class="peek-text">Vil du helst...</div>
<div class="peek-buttons">
<div class="peek-bluebutton"><?php echo $blue_question ?></div>
<div class="peek-redbutton"><?php echo $red_question ?></div>
</div>
</div>
<div class="row text-center" id="textrow">
<h3 style="color:white;">Vil du helst...</h3>
</div>
<div class="row" id="buttonrow">
<div class="col-md-1">
<div class="button-left"></div>
</div>
<div class="col-md-10"><
<div class="col-md-5 col-md-offset-1 button" id="bluebutton">
<div class="blueCheckDiv"></div>
<div id="text-container">
<table cellpadding="0">
<tbody>
<tr>
<td valign="middle">
<div class="result">
<div class="percentage">
<?php
$percent = $blue_votes/($blue_votes + $red_votes);
$percent_friendly = number_format( $percent * 100, 0 ) . '%';
echo $percent_friendly;
?>
</div>
<div class="total-votes">
<span class="count">
<?php echo $blue_votes; ?>
</span>
<span class="word">
enige
</span>
</div>
<div class="question-text">
<?php echo $blue_question ?>
</div>
</div>
<p class="question">
<?php echo $blue_question ?>
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-5 button" id="redbutton">
<div class="redCheckDiv"></div>
<div id="text-container">
<table cellpadding="0">
<tbody>
<tr>
<td valign="middle">
<div class="result">
<div class="percentage">
<?php
$percent = $blue_votes/($blue_votes + $red_votes);
$percent_friendly = number_format( $percent * 100, 2 ) . '%';
echo $percent_friendly;
?>
</div>
<div class="total-votes">
<span class="count">
<?php echo $red_votes ?>
</span>
<span class="word">
uenige
</span>
</div>
<div class="question-text">
<?php echo $red_question ?>
</div>
</div>
<p class="question">
<?php echo $red_question ?>
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-1">
<div class="button-right"></div>
</div>
</div>
<div class="row" id="dividerrow">
<div class="col-md-8" id="divider-left"></div>
<div class="col-md-4" id="divider-right"></div>
</div>
<div class="row" id="socialrow">
<div class="col-md-8 socialcol" id="col-left"></div>
<div class="col-md-4 socialcol" id="col-right"></div>
</div>
I suggested you to use a framework in the comments to your question.
Anyway, to do what you are trying, you can try something like this:
<?php
$id = 1;
if (true === isset($_GET['id'])) {
$id = $_GET['id'];
}
$result = performQuery("SELECT * FROM dilemmas WHERE id = ".$id);
while($row = mysqli_fetch_array($result)){
$blue_question = utf8_encode($row['blue_question']);
$blue_votes = utf8_encode($row['blue_votes']);
$red_question = utf8_encode($row['red_question']);
$red_votes = utf8_encode($row['red_votes']);
}
And you can call this same page with something like example.com/page.php?id=1234.
So, you can build links for each question like this:
Share
NOTE: This is a really dirty code and it opens to a lot of security issues. I wrote it only to make you able to understand the dynamics, but, again, I suggest you to use a framework on the first start: make all in "plain" PHP will cause you to deal with a lot of complex problems like the security or the handling of routing or services, etc... Use a framework to find very good guidance and to learn faster and better the language of your choice (PHP in this case).

Categories