|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26662099 - 05/10/20 10:43 AM (3 years, 8 months ago) |
|
|
Quote:
But what is "SELECT post_id FROM posts WHERE EXISTS(SELECT * FROM posts)" trying to do?!
Its really neat and simple! 
In my case it simply printing post_id from rows that exist!
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26662101 - 05/10/20 10:44 AM (3 years, 8 months ago) |
|
|
Quote:
The while loop will keep loading $row until $result is expended.
This was my biggest obstacle. Coudlnt quite brainstorm the idea behind this
--------------------
|
singlet_oxygen
Stranger
Registered: 05/10/20
Posts: 32
Last seen: 3 years, 6 months
|
Re: Please help me with my website [Re: Gypsy Boy]
#26662107 - 05/10/20 10:50 AM (3 years, 8 months ago) |
|
|
Quote:
Gypsy Boy said:
Quote:
But what is "SELECT post_id FROM posts WHERE EXISTS(SELECT * FROM posts)" trying to do?!
Its really neat and simple! 
In my case it simply printing post_id from rows that exist!
Why wouldn't "SELECT post_id FROM posts" work? (Hint: it absolutely will work!)
-------------------- 1O2
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26662119 - 05/10/20 10:53 AM (3 years, 8 months ago) |
|
|
THIS
Quote:
$sql = ("SELECT post_id FROM posts WHERE EXISTS (SELECT * FROM posts)"); $res = mysqli_query($dbc, $sql);
while($row = $res->fetch_assoc()) {
$id = $row['post_id'];
Is the brain power behind my program and it was doing my head in for the last 24 hours.
Finally works but i dont understand still how exactly it functions.
$res fetches a number of rows in database :
post_id = 12 post_id = 15 post_id = 20
How you work with them 1 by 1 is still not clear
Quote:
The while loop will keep loading $row until $result is expended.
Something to do with that. Every time loop is carried out it displays next mesage.
In C++ that wouldnt work. In C++ you would have to write a loop with a counter...
--------------------
Edited by Gypsy Boy (05/10/20 11:00 AM)
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
|
Quote:
singlet_oxygen said:
Quote:
Gypsy Boy said:
Quote:
But what is "SELECT post_id FROM posts WHERE EXISTS(SELECT * FROM posts)" trying to do?!
Its really neat and simple! 
In my case it simply printing post_id from rows that exist!
Why wouldn't "SELECT post_id FROM posts" work? (Hint: it absolutely will work!)
You need to read all thread buddy, i explain how post_id is not consistent. Read the thread i explained it there
--------------------
Edited by Gypsy Boy (05/10/20 11:07 AM)
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26662136 - 05/10/20 11:02 AM (3 years, 8 months ago) |
|
|
Anyway it is time to get drunk and celebrate!!
All the hard work is now history.
--------------------
|
singlet_oxygen
Stranger
Registered: 05/10/20
Posts: 32
Last seen: 3 years, 6 months
|
Re: Please help me with my website [Re: Gypsy Boy]
#26662137 - 05/10/20 11:03 AM (3 years, 8 months ago) |
|
|
I looked through the thread and nothing explains why you need that clause. "EXISTS(SELECT * FROM posts)" is always true so long as you have a single row in the 'posts' table.
You must have really fucked up your code to need it. I'd encourage you to work out how to fix your code so you don't need it (probably as simple as a "if($res = query())" pattern).
It's up to you of course.
-------------------- 1O2
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
|
Ohh shit u might be right!
--------------------
|
|