|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Please help me with my website
#26649823 - 05/05/20 05:53 AM (3 years, 8 months ago) |
|
|
Making a website in Dreamweaver.
Everything's great except ONE thing
My picture and slogan doesn't appear centred ON MY SAMSUNG S8+ MOBILE device.
It looks just right in Google Chrome, internet explorer AND even on my apple IPad. But for some reason picture appears to the left on my android galaxy S8+
This is doing my head in. I gotta figure out how to fix this. A lot of people use androids 
Heres a quick code :
Quote:
<html lang="en-US"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Finder</title> <link href="singlePageTemplate.css" rel="stylesheet" type="text/css"> <style type="text/css"> body { background-color: #DAE9FB; text-align: center; } </style> </head> <body>
<p> </p> <p> <img src="image.png" alt="" width="537" height="295"></p> <p> </p> <p style="font-size: 18px; text-align: center;">Welcome to my website.</p>
--------------------
|
Moldman
Stranger


Registered: 03/21/20
Posts: 26
Loc: Contamination
Last seen: 2 years, 11 months
|
Re: Please help me with my website [Re: Gypsy Boy]
#26650088 - 05/05/20 08:33 AM (3 years, 8 months ago) |
|
|
Not expert on matter but do you do your testing with Chrome developer tools or like so you can test how webpage looks with click of a button in different resolutions in different devices? Might need to add a custom device with right resolution. If you test with phone instead of Chrome on computer, have you tried different browser in it if that behaves differently? If not, try installing Chrome. Asking this because whatever builtin browser I had in my phone or tablet most sites I visited didn't render properly.
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: Moldman]
#26650469 - 05/05/20 11:35 AM (3 years, 8 months ago) |
|
|
I'll figure it out, might go on samsung/android forums...
Just thought someone here might help
--------------------
|
koraks
Registered: 06/02/03
Posts: 26,670
|
Re: Please help me with my website [Re: Gypsy Boy]
#26651916 - 05/05/20 11:56 PM (3 years, 8 months ago) |
|
|
You have no "center" tag or style element for the title, so it will be displayed according to the default of the browser.
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: koraks]
#26652359 - 05/06/20 07:07 AM (3 years, 8 months ago) |
|
|
Quote:
body { background-color: #DAE9FB; text-align: center; } /quote]
What's that supposed to be?
Like I said it is centred on pc and ipad, it's just my galaxy smartphone
--------------------
|
Ythan
ᕕ( ᐛ )ᕗ


Registered: 08/08/97
Posts: 18,774
Loc: NY/MA/VT Borderlands
Last seen: 17 minutes, 35 seconds
|
Re: Please help me with my website [Re: Gypsy Boy]
#26652686 - 05/06/20 10:38 AM (3 years, 8 months ago) |
|
|
I tested your code in Samsung Browser 11.1.2.2 and the image was centered for me. Are you sure you're zoomed out all the way?

You could try adding something like this to your style but it shouldn't be necessary:
Code:
img { display: block; margin-left: auto; margin-right: auto; }
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: koraks]
#26653021 - 05/06/20 02:03 PM (3 years, 8 months ago) |
|
|
Quote:
koraks said: You have no "center" tag or style element for the title, so it will be displayed according to the default of the browser.
Apart from default declaration i posted above theres also this:
Quote:
<p style="font-size: 18px; text-align: center ;">Welcome to my website.</p>
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26653029 - 05/06/20 02:07 PM (3 years, 8 months ago) |
|
|
Ythan, thanks for stopping by.
I have no clue why my samsung gone rogue on my website.
It would be good to simply post address of my website but i dont want to reveal its content just yet.
I will figure it out one way or the other.
Ohh and this: i started working on my website a months ago. Where on the net should i go for help? Doing everything on your own sucks, in uni id ask tutor and he would solve my problem in 20 seconds, here sometimes i m stuck on a problem sometimes for hours. I guess i could ask for help here... or maybe reddit?
I am glad i got Dreamweaver 2020 CC. Expensive but very practical when coding HTML & CSS. Anyway i am almost done with HTML /Css side of my website, now its to do some heave PHP and MySQL coding.
Will take me couple of months to finish this. Its a cool site, i think u gonna like it
--------------------
Edited by Gypsy Boy (05/06/20 02:25 PM)
|
Ythan
ᕕ( ᐛ )ᕗ


Registered: 08/08/97
Posts: 18,774
Loc: NY/MA/VT Borderlands
Last seen: 17 minutes, 35 seconds
|
Re: Please help me with my website [Re: Gypsy Boy]
#26653225 - 05/06/20 04:07 PM (3 years, 8 months ago) |
|
|
Man that's a good question. These days I don't get stuck on actual HTML very often so I'm usually looking for help with backend stuff. Mostly I just use Google and Stackoverflow. I still haven't come across a problem that isn't already explained somewhere online so improving my Google-fu has probably helped me the most over the years.
But out of all the old forums I have in my bookmarks, it looks like https://forums.digitalpoint.com/ is still alive and kicking, I bet you can get good answers there.
Good luck, I'll be interested to see your site!
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: Ythan]
#26653366 - 05/06/20 05:27 PM (3 years, 8 months ago) |
|
|
Just spent 3 hours heavy coding.
I now can not only print shit from a database but upload "text area" into a database.
My website is pretty simple. Its like a message board but very simplified and without the baggage. (im doing it from scratch btw, not using any packaged message boards)
Today i managed to work out how to gather user submitted data, tomorrow im going to learn how to print it on a page, and the next day how to search / skim thro all bullitens. And im done, alpha phase is over.
--------------------
|
Ythan
ᕕ( ᐛ )ᕗ


Registered: 08/08/97
Posts: 18,774
Loc: NY/MA/VT Borderlands
Last seen: 17 minutes, 35 seconds
|
Re: Please help me with my website [Re: Gypsy Boy]
#26653477 - 05/06/20 06:18 PM (3 years, 8 months ago) |
|
|
Sounds awesome man, it's so gratifying when your first project starts to come together. 
Make sure you read up about HTML and SQL injection attacks before going live with any site that displays or saves user input. It's easy to build an insecure script by accident when you're first getting started but it's also easy to avoid these vulnerabilities once you're aware of them.
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: Ythan]
#26654446 - 05/07/20 05:53 AM (3 years, 8 months ago) |
|
|
God damn it!! made a neat and tidy site i n Dreamweaver...
Load it up in chrome or explorer , its looks messy
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26654507 - 05/07/20 06:50 AM (3 years, 8 months ago) |
|
|
Good God!!!
It looked like shit in WAMP but when i uploaded onto my website it looks just right!!!
--------------------
Edited by Gypsy Boy (05/07/20 08:14 AM)
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26654748 - 05/07/20 09:43 AM (3 years, 8 months ago) |
|
|
Right Ythan, hold on to yer hat 
I am making progress.
In my web app i have 3 options to
1. Advertise / gather user data
2. Browse said data
3. Search for specific data
I have completed first bit very well. Im on my second bit.
I need to know how to format text stored on MySQL into a nice paragraph chunks. I have no idea just yet.

Here is a sample of code i need to fit into 2nd phase. Can you please help me out bud? It will come in text boxes. One goes under the last one. thats it. Nothing fancy
ps. u gotta love Dreamweaver coloration of the code 
All i want is to be able to manipulate data like php text same way you would go about changing html
--------------------
|
stubb
Dahg Rastubfari



Registered: 03/23/19
Posts: 1,310
Loc: Memory
|
Re: Please help me with my website [Re: Gypsy Boy]
#26655378 - 05/07/20 03:21 PM (3 years, 8 months ago) |
|
|
Quote:
Gypsy Boy said: I need to know how to format text stored on MySQL into a nice paragraph chunks.
Don't mean to butt in, but you don't need to do much. If you insert data from a <textarea> into a database, the line formatting will be preserved. In the database it'll look something like "Line one\r\nLine Two\r\n\r\nLine Four". '\r' and '\n' are special characters (ASCII Control Characters) that tell a computer to return the cursor to far left and move it down to a new line.
If you put this data back into a textarea from the database, it will look as it should. In most any other element though, the line formatting won't show (rather, the control codes will print line breaks in the HTML source, which the browser engine ignores). For this php has the nl2br() method, which will convert ASCII \newlines to HTML <br>eaks. Or, HTML has the <pre> tag which will preserve plain-text pre-formatting - whitespace as well as linebreaks.
I'm going to echo Ythan though because it's extremely important you do your homework on injection attacks before going live. A friend of mine once asked me to help attempt some damage control after ending up with a reverse shell on his server via injection - it was an absolute dumpster fire.
--------------------

|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: stubb]
#26655403 - 05/07/20 03:36 PM (3 years, 8 months ago) |
|
|
OK. This is a problem i cannot solve myself.
I cant copy paste code in here for some reason so im attaching a SMALL pic with the code here.
Please help me guys
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: Gypsy Boy]
#26655409 - 05/07/20 03:38 PM (3 years, 8 months ago) |
|
|
Quote:
If you put this data back into a textarea from the database
THATS is what im trying to do. So far i can only output default/standard text on a white screen!! I need to make it look good - like in a colored text box/area!!
--------------------
|
stubb
Dahg Rastubfari



Registered: 03/23/19
Posts: 1,310
Loc: Memory
|
Re: Please help me with my website [Re: Gypsy Boy]
#26655422 - 05/07/20 03:44 PM (3 years, 8 months ago) |
|
|
<textarea> needs to be echoed as string, and <br>'s within the textarea need to be newlines:
while ($resultarr = mysqli_fetch_assoc($result)){ $r1 = $resultarr["message"]; echo "<textarea>" echo $r1, " "; echo "\r\n"; echo "\r\n"; echo "</textarea>"; }
--------------------

|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 days
|
Re: Please help me with my website [Re: stubb]
#26655451 - 05/07/20 03:58 PM (3 years, 8 months ago) |
|
|
Tried that got :
Quote:
Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in C:\wamp64\www\sandbox\html.php on line 27

I have NO idea why it doesnt like line 27
--------------------
|
stubb
Dahg Rastubfari



Registered: 03/23/19
Posts: 1,310
Loc: Memory
|
Re: Please help me with my website [Re: Gypsy Boy]
#26655460 - 05/07/20 04:02 PM (3 years, 8 months ago) |
|
|
Indeed, I missed the ; after 'echo "<textarea>"'
fixed:
while ($resultarr = mysqli_fetch_assoc($result)){ $r1 = $resultarr["message"]; echo "<textarea>"; echo $r1, " "; echo "\r\n"; echo "\r\n"; echo "</textarea>"; }
--------------------

|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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, 25 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!!!
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 2 months, 25 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, 25 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, 25 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, 25 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, 25 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, 25 days
|
|
Ohh shit u might be right!
--------------------
|
|