|
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]
#26655473 - 05/07/20 04:09 PM (3 years, 8 months ago) |
|
|
Silly lol
I just noticed that as awell
--------------------
|
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]
#26655505 - 05/07/20 04:23 PM (3 years, 8 months ago) |
|
|
Still need more help dudes:
Tried to customise teaxtarea:
while ($resultarr = mysqli_fetch_assoc($result)){ $r1 = $resultarr["message"]; echo "<textarea name="party" cols="70" rows="12" maxlength="750" wrap="soft" class="party">"; echo $r1; echo "\r\n"; echo "\r\n"; echo "</textarea>"; echo "<br>"; echo "<br>"; }
It gives error: Parse error: syntax error, unexpected '70' (T_LNUMBER), expecting ',' or ';' in C:\wamp64\www\sandbox\html.php on line 26
What do i do 
Ohh and dont worry i will incluid everyone who helped me in about/credits section of my site !
--------------------
|
stubb
Dahg Rastubfari



Registered: 03/23/19
Posts: 1,310
Loc: Memory
|
Re: Please help me with my website [Re: Gypsy Boy]
#26655522 - 05/07/20 04:32 PM (3 years, 8 months ago) |
|
|
You gotsta escape those quotation marks around the HTML tag attribute values, else php will interpret them as string terminators:
echo "<textarea name=\"party\" cols=\"70\" rows=\"12\" maxlength=\"750\" wrap=\"soft\" class=\"party\">";
--------------------

|
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: stubb]
#26655599 - 05/07/20 05:05 PM (3 years, 8 months ago) |
|
|
I COULD KISS YOU
5 shrooms
--------------------
Edited by Gypsy Boy (05/07/20 05:11 PM)
|
stubb
Dahg Rastubfari



Registered: 03/23/19
Posts: 1,310
Loc: Memory
|
Re: Please help me with my website [Re: Gypsy Boy]
#26655688 - 05/07/20 06:01 PM (3 years, 8 months ago) |
|
|

No prob, happy to help!
--------------------

|
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: stubb] 1
#26656677 - 05/08/20 06:04 AM (3 years, 8 months ago) |
|
|
Well as of this morning, 2/3rds of my website is done.
I am yet to implement anti hacking steps.
I figured id do that after alpha/beta release.
So, i can now post my bulletin items, browse said items, All i need to do now is be able to search thro them , based on a really neat algorithm - post code search - compare 2 post codes and output bulletins which go under a certain amount of miles. 
A BIG thank you to all who helped.
--------------------
|
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]
#26660160 - 05/09/20 02:28 PM (3 years, 8 months ago) |
|
|
Moving onto the next Step
Last part of my website:
1. Acquire target postcode and distance thro html form
2. Compare given postcode with every postcode in the table
3. Figure out how far post codes are between each other
4. If given post code and database postcode is within given distance
5. Print that row/text area in database where distance is under the limit
I got it all sorted except one thing:
how do I compare given postcode with a post code in the database as there can be any number of rows / postcodes??
If I knew say there 20 rows, I would just use
For(counter =1; counter< 20; counter++) Compare and Print all 20 boxes/records/row
But there is no fixed number of rows in my table. It can be 20, it can be 2000
Columns In my table There’s : post_id Message Email Town Date Postcode
See what I’m saying? I need to circulate through all postcodes in the table, and there’s no way of knowing how many rows there are. All there is a auto increment post_id column : and every time someone posts a new record post_id gets a unique auto increment number which I use to retrieve and compare postcodes.
Sorry but I tried my best to explain, hope u understand what I’m saying.
I need some kind of algorithm that loops thro post_id column until there no more of them, at which point the loop stops.
--------------------
|
stubb
Dahg Rastubfari



Registered: 03/23/19
Posts: 1,310
Loc: Memory
|
Re: Please help me with my website [Re: Gypsy Boy]
#26660314 - 05/09/20 03:59 PM (3 years, 8 months ago) |
|
|
*** I've confused myself, don't wanna confuse you. I'll reedit when I get my shit together. *** 
You can simply use a while loop:
$result = mysql_query("SELECT * FROM address_table"); while($row = mysql_fetch_array($result)) { // compare to $row['postalcode']; }
Edited by stubb (05/09/20 04:40 PM)
|
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: stubb]
#26661682 - 05/10/20 05:58 AM (3 years, 8 months ago) |
|
|
Did you mean mysqli_query instead of mysql_query??
--------------------
Edited by Gypsy Boy (05/10/20 06:36 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]
#26661684 - 05/10/20 05:59 AM (3 years, 8 months ago) |
|
|
Lets go over this again:
Connect to the database
Start while loop (need help here)
{ compare 2 postcodes
fetch east from HTML form postcode A fetch north from HTML form postcode A
fetch east from FIRST ROW postcode stored in database fetch north from FIRST ROW postcode stored in database
Calculate distance between 2 postcodes. (first code from HTML second code from database)
IF (distance is WITHIN specified range) { print FIRST ROW textarea }
} // end of while loop
Seems simple but its not. Because 2nd time the loop runs it needs to be SECOND ROW postcode. And then the loop must end when it reaches last postcode row entry in the database.
--------------------
Edited by Gypsy Boy (05/10/20 06:06 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]
#26661704 - 05/10/20 06:16 AM (3 years, 8 months ago) |
|
|
a word about my database tables:
first table called postcodes - 3 columns: east, north and postcode.
Second table called "posts"
6 columns: post_id message email date town postcode
post_id is primary key and its auto increment.
If you look at database you'll see rows going
post_id 12 postcode "NE3 SUE" post_id 15 postcode "DD3 8IN" post_id 20 postcode "Gl53 "ES"
And so on. Theres a gap in post_id - it doesnt go evenly 1 2 3 4 5 , cos some rows need to be deleted - hence the gap.
HOW do i implement post_id into postcode comparison?
--------------------
|
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]
#26661731 - 05/10/20 06:34 AM (3 years, 8 months ago) |
|
|
I tried 2 loops:
One you gave me
Quote:
$sql = ("SELECT post_id FROM posts"); $sqlresult = mysqli_query($dbc, $sql); while($row = mysqli_fetch_array($sqlresult))
Error: Object of class mysqli_result could not be converted to string
And one of mine:
Quote:
$sql = ("SELECT post_id FROM posts"); $sqlresult = mysqli_query($dbc, $sql); $resultarr = mysqli_fetch_assoc($sqlresult); $resultid = $resultarr["post_id"]; while($resultid)
Produces rogue unlimited loop 
Dude, i appreciate your help. If you help me thro this i will share some benefits with you
--------------------
Edited by Gypsy Boy (05/10/20 06:51 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]
#26661800 - 05/10/20 07:33 AM (3 years, 8 months ago) |
|
|
Alright, i seem to be moving somewhere:
First of all, my barebones code works.
For example i fetch postcode stored in post_id 12. And i get my textarea printed.
What i did i used
SELECT COUNT(post_id) FROM posts
And it gives me number of records in my table.
For example it gives me 3.
All i do is create a count variable and then assign it 3 and run loop 3 times prionting all my 3 posts.
if it was that easy Like i said my primary key post_id variable does no abide to number 3. At teh start of table life it went 1 2 3... but some records have been deleted and now it looks like 12, 15, 20 etc..
Get my drift?
How do i implement count that only counts existing post_id rows?
--------------------
|
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]
#26661812 - 05/10/20 07:44 AM (3 years, 8 months ago) |
|
|
NOW we getting somewhere
I used:
Quote:
SELECT post_id FROM posts WHERE EXISTS (SELECT * FROM posts);
And it came up with a valid response:
12
14
15
So as you can see there 3 rows with post_id numbers in them.
Now i need to implement this into my loop somehow.
If i use:
Quote:
$sql = ("SELECT post_id FROM posts WHERE EXISTS (SELECT * FROM posts)"); $result = mysqli_query($dbc, $sql);
Will it store all 3 numbers in $result?
How do i separate them ?
|
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]
#26661846 - 05/10/20 08:17 AM (3 years, 8 months ago) |
|
|
Quote:
Gypsy Boy said:
Will it store all 3 numbers in $result?
How do i separate them ?
Sorry haven't been through all the replies in the thread.
Most people would use this pattern:
Code:
$result = $conn->query("SELECT post_id..."); while($row = $result->fetch_assoc()) { echo $row['post_id']; }
Making sure first at least one result is returned ($result->num_rows).
If you only want 3 rows returned use LIMIT in your query like "SELECT post_id ... LIMIT 3".
-------------------- 1O2
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
|
Right 
I just tried
Quote:
$test = ("SELECT post_id FROM posts WHERE EXISTS (SELECT * FROM posts)"); $result = mysqli_query($dbc, $test); $resultarr = mysqli_fetch_assoc($result); $r1 = $resultarr["post_id"]; echo $r1;
And the answer printed was "12" !!
What happened to 14 and 15? how do i retrieve them?
--------------------
|
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]
#26661913 - 05/10/20 09:06 AM (3 years, 8 months ago) |
|
|
singlet_oxygen, hows it going buddy, thanks for stopping by and helping!
Im gonna try yer code now.
$result = $conn->query("SELECT post_id..."); while($row = $result->fetch_assoc()) { echo $row['post_id']; }
Im a little confused tho
Whats variable $row about?? I dont see it declaring anywhere
|
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]
#26661930 - 05/10/20 09:18 AM (3 years, 8 months ago) |
|
|
$sql = ("SELECT post_id FROM posts WHERE EXISTS (SELECT * FROM posts)"); $result = mysqli_query($dbc, $sql);
while($row = $result->fetch_assoc()) { echo $row['post_id']; $id = $row['post_id']; echo "\r\n"; echo "\r\n"; echo $id;
Seems to work
--------------------
Edited by Gypsy Boy (05/10/20 09:44 AM)
|
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]
#26661943 - 05/10/20 09:25 AM (3 years, 8 months ago) |
|
|
Quote:
Gypsy Boy said: singlet_oxygen, hows it going buddy, thanks for stopping by and helping!
Im gonna try yer code now.
$result = $conn->query("SELECT post_id..."); while($row = $result->fetch_assoc()) { echo $row['post_id']; }
Im a little confused tho
Whats variable $row about?? I dont see it declaring anywhere
I've highlighted to show where it's declared.
fetch_assoc will return a associative array variable which we load into $row.
The while loop will keep loading $row until $result is expended.
If you click that link you can see it in action in the examples, I prefer OO style.
Edit: Just seen your $conn error, I guess I will have to read the other replies serves me right for just jumping in. I recommend you look at the link above for fetch_assoc and make your code look like the idiom either Example 1 (object orientated) or Example 2 (procedural) style.
https://www.shroomery.org/forums/showflat.php/Number/26654748#26654748 The code you screenshot here looks good (it's idiomatic procedural style).
Quote:
Gypsy Boy said: Right 
I just tried
Quote:
$test = ("SELECT post_id FROM posts WHERE EXISTS (SELECT * FROM posts)"); $result = mysqli_query($dbc, $test); $resultarr = mysqli_fetch_assoc($result); $r1 = $resultarr["post_id"]; echo $r1;
And the answer printed was "12" !!
What happened to 14 and 15? how do i retrieve them?
Try:
Code:
$test = ("SELECT post_id FROM posts");
if($result = mysqli_query($dbc, $test)){ while ($resultarr = mysqli_fetch_assoc($result)) { $r1 = $resultarr["post_id"]; echo $r1; } }
But what is "SELECT post_id FROM posts WHERE EXISTS(SELECT * FROM posts)" trying to do?!
-------------------- 1O2
Edited by singlet_oxygen (05/10/20 09:33 AM)
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 24 days
|
|
while($row = $result->fetch_assoc()) { $id = $row['post_id'];
echo $id; }
Works!!!!
I finally did it. Everything seems to work fine.
Pheeewwwwwww... took me a while
HUGE THANK YOU to all who helped.
We havent finished yet, there gonna be more questions. But alpha/beta stage of my website is now complete!!!
--------------------
|
|