João Gonçalves João Gonçalves - 27 days ago 7
PHP Question

select all rows with sport=padel

i want to select all the content of the row when sport= padel.

My code is this:

$result = mysqli_query($con,"SELECT sport FROM posts WHERE sport='padel'
");
while($row=mysqli_fetch_assoc($result)){ ?>

<div class= 'box1'>
<p align='middle'><?php echo $row['username']; ?></p>
<h3 align='middle'>Playing</h3>
<h3 align='middle' style= 'color:blue'><?php echo $row['sport']; ?> </h3>
<div><p align='middle' >Disponibilidade:</p>
<h3 align='middle' style='color:blue'><?php echo $row['text']; ?></h3></div>
<p></p>
<h3 align='middle' style='color:blue'><?php echo $row['city']; ?></h3>
<button text-align='middle' id='submit1' type='submit1'>
contact </button>
</div>


This in fact select all the row whith sport=padel, but all the other cotent in the diferent columns is missed (gives me undifined variable)

I think i could do this:

$result = mysqli_query($con,"SELECT sport FROM posts WHERE sport='padel'
WHERE text='' WHERE city=''");


but didnĀ“t work. Can anyone help me?

Answer

As others have mentioned in the comments, you need to specify what columns you want to pull back, at the moment you are pulling back the sport column only.

SELECT * FROM posts WHERE sport="padel"

This will ensure you pull back all columns. Alternatively you can specify multiple comma separated columns

SELECT col1, col2, col3 FROM posts WHERE sport="padel"