|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
PHP and MySQL gurus !!
#26502001 - 02/24/20 05:49 PM (4 years, 2 months ago) |
|
|
I am working on a website...
could someone please help
I am just starting this. Basically i wrote a simple code that fetches a table thro PHP and then prints its content. Heres the code:
$sql = ("SELECT name FROM forums"); $result = mysqli_query($dbc, $sql); $resultarr = mysqli_fetch_assoc($result); $r = $resultarr["name"];
echo $r;
It works. But, it only prints the top value in the table - just 1, wheres SELECT in SQL lists entire table. How can i make it show the table in one go?
--------------------
Edited by Gypsy Boy (03/15/20 08:51 AM)
|
audiophoenix
Find Peace


Registered: 08/28/09
Posts: 4,107
Loc: Upstate NY
Last seen: 3 years, 15 days
|
Re: PHP and MySQL gurus come in here!! [Re: Gypsy Boy]
#26502018 - 02/24/20 05:56 PM (4 years, 2 months ago) |
|
|
It's so funny how people post on a mushroom enthusiast website for hep with the weirdest things
--------------------
|
Ythan
ᕕ( ᐛ )ᕗ


Registered: 08/08/97
Posts: 18,840
Loc: NY/MA/VT Borderlands
Last seen: 9 hours, 48 minutes
|
Re: PHP and MySQL gurus come in here!! [Re: Gypsy Boy]
#26502302 - 02/24/20 08:54 PM (4 years, 2 months ago) |
|
|
You just need to loop through the results, like this:
Code:
$sql = ("SELECT name FROM forums"); $result = mysqli_query($dbc, $sql);
while ($resultarr = mysqli_fetch_assoc($result)) { $r = $resultarr["name"]; echo $r; }
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: PHP and MySQL gurus come in here!! [Re: Ythan]
#26502619 - 02/25/20 05:58 AM (4 years, 2 months ago) |
|
|
Hey dude thanks VERY much for help
It worked but now got another problem on my hand.
I use HTML form to type in country name:
<form method="post" action="action.php"> <div class="center"> <p>Language</p> <input type="text" name="language" value=""> <br> <p>Show countries</p> <input type="submit" name="submit" value=" Go "> <br>
Basically u type a language and it print outs all countries that speak it name
For some reason forum wont let me post php code so im attaching image
--------------------
Edited by Gypsy Boy (02/25/20 07:47 AM)
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: PHP and MySQL gurus come in here!! [Re: Gypsy Boy]
#26502660 - 02/25/20 06:55 AM (4 years, 2 months ago) |
|
|

Gives this error
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in C:\wamp64\www\world\action.php on line 26
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: PHP and MySQL gurus come in here!! [Re: Gypsy Boy]
#26502669 - 02/25/20 07:05 AM (4 years, 2 months ago) |
|
|
Funnily enough simple script like this:

Works just fine 
What the hell is wrong with world database?
So frustrating, i need a smoke
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: PHP and MySQL gurus come in here!! [Re: Gypsy Boy]
#26502696 - 02/25/20 07:27 AM (4 years, 2 months ago) |
|
|

This is getting fkin ridiculousness
I used WORKING code from small "forum" database and replaced variable names with world database. I get same
mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in C:\wamp64\www\world\action.php on line 26
error 
BTW i used pics for code because forums woudlnt let me post it in text for some reason
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: PHP and MySQL gurus come in here!! [Re: Gypsy Boy]
#26502705 - 02/25/20 07:39 AM (4 years, 2 months ago) |
|
|
I finally got it 

$sql = ("SELECT name FROM country WHERE Continent = '$name'");
$name had to be double quoted cos it's a string I suppos
How the hell compiler didnt provide a meaningful error message?????
--------------------
Edited by Gypsy Boy (02/25/20 08:49 AM)
|
|