Aeonix 71 Posting Whiz
SELECT topics.id topicId,
      topics.name topicName,
      topics.closed topicClosed,
      forums.lastTopicId forumLastTopicId,
      forums.topicCount forumTopicCount,
      forums.description forumDescription
FROM forums INNER JOIN members ON forums.lastPoster = members.id

The query isn't working at all, so I tried finding if query is incorrect, but before that I need to make the query work, to figure out why it's not working, to figure out how to fix it, so I can get result, which doesn't bring the result, it brings false.

Aeonix 71 Posting Whiz

SHOW CREATE TABLE topics

+--------+-----------------------------------------------+
| Table  | Create Table                                  |
+--------+-----------------------------------------------+
| topics | CREATE TABLE `topics` ( `id` int(9) NOT NULL  |
|        | AUTO_INCREMENT, `name` varchar(24)            |
|        | CHARACTER SET utf8 NOT NULL, `closed`         |
|        | int(1) NOT NULL, `postCount` int(9) NOT NULL, |
|        | PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`),   |
|        | KEY `id_2` (`id`)) ENGINE=MyISAM              |
|        | AUTO_INCREMENT=2 DEFAULT CHARSET=latin1       |
+--------+-----------------------------------------------+
Aeonix 71 Posting Whiz

Yes, I know. Table topics and within column id exists. This error occurs.

Aeonix 71 Posting Whiz

Unknown column 'topics.id' in 'field list'

SELECT topics.id topicId, [...]

topics.id DOES exist.

Aeonix 71 Posting Whiz

I don't think it's code-bound, but here's the code: http://pastebin.com/yWJ5qpwN

What happens is... I input 2 different passwords, line 22 is for some reason entirely skipped. The script passes every verification, the SQL record is added, and further execution of code happens. User gets logged in and moved to index.php as if nothing happened. Obviously, I want it to verify username, password match and email, none of that happens, too bad.

What I did was comment-out redirect on line 43. Now the user is getting redirected towards message that passwords don't match, but user is getting logged in, even with the mismatch of passwords!!

How does that even happen? Doesn't PHP execute code line by line?

Aeonix 71 Posting Whiz

Exactly that!

Aeonix 71 Posting Whiz

I need to create about 1000 users, with random (but normal looking names not "293dsaf81s234" but "Blue Air" (can be random dictionary words)). And I need to generate topics and posts, and many others things. Does anybody know a good way on how to generate dummy content in PHP? What would be the good approach?

Aeonix 71 Posting Whiz

Usually if you're using PHP 5.4 and above this is the default,

"PHP Version 5.6.21"

But what if I cannot install anything? This isn't my server. I'm using hosting.

All I get to do is choose PHP version. PHP 7, 5.5 and 5.6 don't seem to work.

Aeonix 71 Posting Whiz

And what about getting results?
Also, I started new topic here https://www.daniweb.com/programming/web-development/threads/504756/return-array-from-prepared-statement
Since it seems to be seperate problem.

Aeonix 71 Posting Whiz

HA! I knew it I got it right, but it doesn't work:
Fatal error: Call to undefined method mysqli_stmt::get_result() in /###/###/###.php on line 47 or more descriptive:

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::get_result() in /###/###/###.php:47 Stack trace: #0 {main} thrown in /###/###/###.php on line 47

That's your line: $result = $stmt->get_result();

If it was that easy, I wouldn't ask this question
I did Google solutions before you know :D ?

Aeonix 71 Posting Whiz
$stmt = $dbconn->prepare("SELECT * FROM `members` WHERE username=? AND password=?");
$stmt->bind_param("ss", $username, $password);

Is what I have. Database is connected etc.
How can I set variable called $dbresult with array of SQL result? I don't want to set individual variables. I really need an entire array as answer. There's couple answers but some of them are outdated ("such function doesn't exist in this namespace") and others involve 10+ lines of code-functions that should actually be shorter. What is a clean and finite way to extract entire array out of prepared statement?

Aeonix 71 Posting Whiz

var_dump($stmt->fetch()) returns true. LOL. No s#!t Sherlock!

How do I bind resulted array into the bind_param so far rifling through internet forces me to create external function. But there must be smaller way.

mysqli_stmt::get_result() and many others are "called to undefined method"...

Aeonix 71 Posting Whiz
$stmt = $dbconn->prepare("SELECT * FROM `members` WHERE username=? AND password=?");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$dbresult = $stmt->fetch();
echo $dbresult; // null
$stmt->close();

Any ideas? I think I store variable, but I don't apparently... could you lend me a hand? ;)

Aeonix 71 Posting Whiz

Read the documentation to see the data types you can define: http://php.net/manual/en/mysqli-stmt.bind-param.php

Once again, I've been to manuals, this is where I got this example from :D

But yea, I see now, in bind_param I define the types in first string, and then pass the references for each as argument.

But what is $stmt->bind_result($district); does it just store result in $district?

Is this correct:

    $stmt = $mysqli->prepare("SELECT * FROM `members` WHERE username=? OR email=?");
    $stmt->bind_param("ss", $username, $email);
    $stmt->execute();

    if ($stmt->num_rows > 0) {
        echo "User found!"
    }
    $stmt->close();

?

Aeonix 71 Posting Whiz
$city = "Amersfoort";

if ($stmt = $mysqli->prepare("SELECT District FROM City WHERE Name=?")) {
    $stmt->bind_param("s", $city);
    $stmt->execute();
    $stmt->bind_result($district);
    $stmt->fetch();
    printf("%s is in district %s\n", $city, $district);
    $stmt->close();
}

This brings many questions:
- What is s on the line 4? Do I need to bother with that?
- What if I needed two conditions on SQL query? SELECT something FROM table WHERE x=? OR y=??
- Why bind_param("s", $city) and not bind_param("daniweb", $city)? How does that affect query anyhow if the only usage is below when echoing?

I've been told to used "bind params" in other topic on here. But I don't understand it.

Aeonix 71 Posting Whiz

THAT'S SO STUPID... QUOTE IS QUOTE.. :|
Oh well. Not my rules... not my game... thanks.

Aeonix 71 Posting Whiz

INSERT INTO 'members' ('username', 'password', 'email') VALUES ('axe', 'axe', 'weql')

-

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''members' ('username', 'password', 'email') VALUES ('axe', 'axe', 'weql')' at line 1

Aeonix 71 Posting Whiz

PERFECT.

And the AS helps too (with u.NAME AS USER_NAME), I can command SQL to give me what I want, instead of taking time to parse it in PHP.

Thank you everybody, through reusing and rereading the logic, I will learn a lot! This is WAY better than making 5 different requests and receiving tons of useless data.

Aeonix 71 Posting Whiz

OH! I thought the first SELECT XYZ was about forums, not about users.

And this other way around :P? How do I select specific elements of both sides?
Let's say users.ID, users.NAME and forums.NAME, forums.DESCRIPTION.

Sorry for making you do this, it's just, tutorials don't explain it pretty well, the only text I found useful around the net is couple posts above by hielo.

Oh and is it possible to mash more than 2 tables? Like 3, 4, 5? That could make for a killer query, instead of 5 different ones.

Aeonix 71 Posting Whiz

One more question though.

SELECT * FROM forums INNER JOIN users ON forums.lastAuthorID = users.id
requests all data from both tables. How could I request id, name only from users for example?

LEFT JOIN seems to be key (I'm searching).

Aeonix 71 Posting Whiz

Yes! Now it's much clearer, now let me read this 5 times and take about 1 minute to process each word, then I'll understand it ;)

But thanks. As you explain it I may understand it fluently soon (I have more grasp on it now).

Aeonix 71 Posting Whiz

Okay, maybe different way, something else that could help me understand this and morph into my needs.

I list forums. From table forums The results are Name|Description|LastAuthorID.
The results are for example Forum1|Description1|1.

I have table users. And I'd like to get name of the user of the ID of LastAuthorID.
Something like SELECT * FROM users WHERE id=LastAuthorID. For each matched result.
So that I will have name of forums, description of forum, id of last poster, name of last poster, rank of last poster (etc. etc. etc. etc.)

I tried this:
SELECT * FROM forums U LEFT JOIN members ON R.lastTopicAuthor = U.id
errors in:
#1054 - Unknown column 'R.lastTopicAuthor' in 'on clause'. Swapping id and lastTopicAuthor doesn't help.

Also, the link you provided, I've been there, but I can't understand jack out of it, that's why I came here.

Aeonix 71 Posting Whiz

I think this is called "foreign key" and "local key" ?

I have a table users, these users have rank. It's an int.
There is a table named rank, this table has field where hexadecimal string is placed FF0000. Is there a way to SELECT * FROM users and SELECT * FROM rank WHERE id=users.rank... or something?

Aeonix 71 Posting Whiz

I'm trying to do something, but it doesn't work out, the primary suspect is incorrect query, but I don't know whether it's correct or not. I could try running it in phpMyAdmin, but then I don't know how these are escaped. The result is: array(5) { ["current_field"]=> NULL ["field_count"]=> NULL ["lengths"]=> NULL ["num_rows"]=> NULL ["type"]=> NULL }. So I figured maybe the query, maybe something else.

mysqli_query("SELECT * FROM members WHERE email='" . $_POST["inputEmail"] . "' OR username='" . $_POST["inputUsername"] . "'");

Does this get parsed properly? Given that $_POST's are alphanumerical?

Aeonix 71 Posting Whiz

Link is: /example.php?id=1, no space after 1.

if (isset($_GET["id"])) {
    $id = $_GET["id"];
    echo !is_int($_GET["id"]);   // yields "1" (true) !!!
}

Ask me whatever you need.

I check to make sure that my system didn't go crazy !is_int(1) yields false. So... I don't know...

Maybe $_GET passes "1" instead of 1. But how do I cast integer in PHP, when it's all handled in background?

Edit: string(1) "1", yep, string. How can I check $_GET["id"] as integer against is_int()?

Aeonix 71 Posting Whiz

I worked it out:

if ($var1 = mysqli_query($databaseconn, "YOUR_SQL_QUERY")) {
    while ($row = mysqli_fetch_assoc($var1)) {
        // $row is associative array.
    }
}
Aeonix 71 Posting Whiz

To add:

For the second problem, the var_dump of your row above shows what's wrong there. 'name' isn't a key in the array, everything is index based.

How come first character of every row is getting outputted? I don't have any other printing running.

Aeonix 71 Posting Whiz

Firstly, this line only showing one row: You've only asked it to fetch one row so the dump only has one row. mysqli_fetch_row does just what it says i.e. it returns ONE row.

mysqli_fetch_assoc doesn't solve it either. mysqli_fetch_rows doesn't exist. How can I fetch all the results? I remember using this some time ago, which doesn't work now, that means that I'm pretty close to the ultimate solution. mysqli_fetch_array results in only first row.

Aeonix 71 Posting Whiz

Connection is successful. No typo's were made (look below). If read it from top to bottom, some of the tests that I show you will seem stupid. Until you look at the end (still keep reading from top to bottom) and find out that it's one of the indicators.

SQL command SELECT * FROM forums, results in the only two rows in forums being shows. 2 rows, 8 columns, exactly as it should be.

Database has been connected. PHP says:

$result = mysqli_query($dbconn, "SELECT * FROM forums");
var_dump($result);

Brings:

object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(8) ["lengths"]=> NULL ["num_rows"]=> int(2) ["type"]=> int(0) }

Especially this part: ["num_rows"]=> int(2).

Next line:

$result = mysqli_fetch_row($result);
var_dump($result);

Results in only first row being shown:

array(8) { [0]=> string(1) "1" [1]=> string(11) "Primo Forum" [2]=> string(23) "Primo Forum Descriptini" [3]=> string(3) "F00" [4]=> string(1) "0" [5]=> string(11) "11Exampleur" [6]=> string(4) "1234" [7]=> string(4) "9991" }

2nd row missing, even though they're next to each other, in same table, matches query, and is being found by the SELECT query, but... doesn't show.

Now for the weirdest stuff. Saying:

$result = mysqli_query($dbconn, "SELECT * FROM forums");
$result = mysqli_fetch_row($result);

foreach($result as $data) {
    echo $data["name"];
}

Gives:

Warning: Illegal string offset 'name' in C:\###\index.php on line 21
1
Warning: Illegal string offset 'name' in C:\###\index.php on line 21
P
Warning: Illegal string offset 'name' in C:\###\index.php on line 21
P
Warning: Illegal string offset 'name' in C:\###\index.php on line 21
F …
Aeonix 71 Posting Whiz

Not quite. Floating to the right, gives about the same result. The problem with it, is that the red part needs to be vertically centered and on the right. Which I succeeded, one or the other, never both at the same time.

Aeonix 71 Posting Whiz

This is element that I'm trying to achieve: http://i.imgur.com/9XmGXkt.png
This is "template" of what I have to work with: https://jsfiddle.net/hcgpyutj/

I tried floating, staticing, absoluting, relativizing, tables, transform. I changed file about 10 times and of each situation something went wrong one way or another. I cannot use flexbox. I don't have any other ideas. I'm out. I don't know.

I don't know height of the parent div (it is set by padding + font-size). I would really need it centered vertically and on the right side. With objects within "here"-div, also being vertically middle aligned.

Could someone help me out on this?

https://jsfiddle.net/hcgpyutj/1/

Aeonix 71 Posting Whiz

Yep, it works.

Still pretty stupid though, every single browser does it, except IE... I don't know what I expected.

Aeonix 71 Posting Whiz

I don't know. But here's the link to download of the project file. Just open the file in Internet Explorer 11 and any other browser, you don't need to do anything, you'll notice the difference right away.

http://expirebox.com/download/752aa6f5c2cba1ea53f50ddcbdb9d406.html

Aeonix 71 Posting Whiz

Yes. I know it works with Internet Explorer 9+ normally. That's why I used it. Because I expected it to work, and it doesn't. I don't know what part does or does not work with it.

Aeonix 71 Posting Whiz

Ah, good you reminded me, I added <!DOCTYPE html>.
However, that still does not solve the problem.

Aeonix 71 Posting Whiz

Didn't work :(

Aeonix 71 Posting Whiz

CSS file: http://pastebin.com/tBvGjhTX
HTML file: http://pastebin.com/r5YUTHgp

I have a div with following rules:

{
    width: 75%;
    margin: 5% auto;
}

Obviously works everywhere except Microsoft Internet Explorer 0.5 to Edge. While in every normal browser, box takes 75% of width and is centered horizontally. But Microsoft be like "screw that", and in Internet Explorer box takes 100% the width of the parent. Any other dependencies, removing them or keeping them doesn't change anything.

Aeonix 71 Posting Whiz
<!-- example -->

<html>
    <head></head>
    <body>
        /* Lots of contents, header, etc.
        <?php
            if (isset($_GET["id"])) {
                echo $anexample[$_GET["id"]]["test"];
            }
        ?>
    </body>
</html>

There would be links that would say example.php?id=1 and id=5 and id=9. However I'd like page to rerender just that particular place. Nothing else in page will change. Is it possible (with usage of JavaScript and jQuery) to change content (by reprocessing this PHP snippet) without reloading the webpage? I know I can use AJAX and use external PHP file to obtain the answer, but still, I'd like to avoid calling external files.

Aeonix 71 Posting Whiz

I would let PHP format it into the array so that the browser just has to JSON.parse() the value and then you don't have to worry about "processing"

It will be straight JSON, that will be JSON.parse()d, I won't eval anything, they're ready to use values, strings and integers.

if you do a straight up for (;;) loop, and you have 100000 results, you will likely be sitting for a while to process all of that (seconds, if not minutes)

What would happen, if I had this entire 100000 entries, and I would for(;;) 100 results? Would that hurt that much?

if they are strings, etc... or what actions you are taking with the data as you iterate over your array.

Just display, document.getElementById("result" + x).innerHTML = oneofresults[x];.

Really, the only way to "know" is to make an HTML page that has your 5MB of data on it already formatted as you need it

This will take A LONG time... also, why HTML page? The result comes from SQL databased, that is parsed into usable array in PHP, then json_encode(), passes through AJAX to front-end JavaScript, the JSON.parse() into a variable, and use it. Where does HTML come from?

So... what are you trying to accomplish? And why all that data? Why must it be that much?

Knowing my skill to explain things, it will only take 5 years to get my point over. So let's just skip why and …

Aeonix 71 Posting Whiz

If user issues a query, I would like AJAX to download the result of query into browser so that JavaScript can do the parsing. The results could be around 1MB-5MB (at most, doubt it would get anywhere near 0.1MB), and I would send it from PHP to front-end using JSON, then convert it into array, which I would then parse depending on users expectations. Given that 57KB is what my asset is worth (project not finished), DaniWeb is for example 1.232kB (as my browser receives it). Would containing 5MB of data in a single array-variable hurt the performance of a computer browser? I'm not talking about download, I'm talking after it's done. Will containing 5MB and making data[2198124]["text"] hurt a lot?

Aeonix 71 Posting Whiz
OH

It's inline-block for children. I somehow manage not to save file, that's why it didn't work.

Aeonix 71 Posting Whiz

Example.

I have parent div of 1000px width. I have 4 children divs that each have been told to have "some size" (for example 300px). I would like to put 3 children in first row and then put the fourth in the second row below the 1st child. Something like flex-wrap: wrap; with flexbox, two scenartio's here:

  • I cannot use actual flexbox (since it would stretch 4th child to 1000px width) and IE9 needs to be supported... because people wish so... and JavaScript needs to be assumed as turned off.
  • Situation as above, but JavaScript is turned on.
Aeonix 71 Posting Whiz

overflow: hidden it is.

Aeonix 71 Posting Whiz

My first problem was.
"I have this box, I need this box to be 230px, and I have second box, that needs to take entire space remaining".

My solution to this was, float. So I floated both boxes, float: left; and float: right. That looked nice, until I noticed that parent box had 0 height, because it was the height of largest item that wasn't floated and because there are no objects without float, it defaulted to height: 0, the only way I've seen box, it's because of padding it had.

So after some Googling, I noticed a solution, overflow: auto, this forced parent to wrap itself around ALL objects (including floated ones) which nicely wrapped. The gave birth to another problem.

In some browsers (ahemFirefoxahem), on some ocassions it produces scroll on the side. Which is what I want to avoid.

While you can't see the last problem in this example, this is something I work with:
https://jsfiddle.net/h9h5fhst/

How else could I align two DIVs next to one another without flexbox and float?

Aeonix 71 Posting Whiz

Is there a way to prepare 80GB HDD (SATA) in such way, that it boots from ISO on itself?

I'm delivering this to an old grandpa who doesn't know a lot about software (he's electrical genius though). I will create steps on how to get through installation. But I need to get this HDD to him (it's too late to buy CD/DVD and I have only my own USB).

I want him to start computer, put this HDD in, restart computer, get through installation and use ye oldie Windows XP x86. How do I do that? :)

I will leave empty partition for the ISO and another one enough to install Windows XP on it. Doable?

PS: He's running pretty old hardware, PC was a top-notch hardware 11 years ago. Including GeForce 6600, 4GB of RAM, Celeron 2.66GHz. It did run Linux Ubuntu Live-CD (from USB) last time I was there though.

Aeonix 71 Posting Whiz

This is essentially a really long question

If I were to create a function without calling it's execution. Does PHP initialize it anyhow or is the entire function ignored entirely without even bothering to read it?

Another way to put it:

Is there any execution difference between code that does have function Example() defined and one that doesn't? In both cases when it's not called?

(don't ask "WHY WOULD YOU NEED TO KNOW IT", just, just, just, just, just, just, just, just, just, answer, just answer)

Aeonix 71 Posting Whiz

Your final question is "How can I determine if a request is from AJAX ?"

No, not really. Because I "send AJAX requests" myself too.

(accept from rude joking replies)

Quote me on that one. I don't recall offending anybody or making fun out of someone, especially where I can't specify my problem. For about 5th time, i just don't word good, u know

So choose a question (and stick to it) , try it understand first

I do understand my question, but you don't, because I don't know how to explain it the way you would understand it.

is that you are not willing to learn

If I didn't want to learn, I wouldn't care and I wouldn't sit here put 2 long posts trying my absolute best to explain myself out of my problem. If I didn't care, I wouldn't put up some virtual examples above, and certainly; if I didn't want to learn, I wouldn't be on DaniWeb. After all that's the website's about.

I'm fairly sure, I spend on this topic alone, about 10 times more time than average poster in here, and I'm still seeking answer.

even if it means that you should try the answers in coding and not in words.

Well that's the core of the issue is.

Aeonix 71 Posting Whiz

Don't mind me, what is VCS? The only thing that pops up in Google (thank you hellish SEOs) is Veritas Cluster Server.

Aeonix 71 Posting Whiz

I know that it's possible for speakers to repeat whatever sound comes into microphone.

But, now I'm thinking. When I speak on Skype/TeamSpeak (VoIP software), would it be possible for me, to select audiofile and play it as if it was sent through microphone?

To send music through my "microphone" and microphone has no actual involvment, but software is managing it this way, that every program that listens to my microphone, gets to hear the sound in high quality (higher*).

Of course I could give them link, or title, but still, I'm heavily interested whether it's possible.

(question involves Linux, any custom type really, Ubuntu, Arch, Slackware, what you not)

Aeonix 71 Posting Whiz

Lately I came up with another idea on how to represent what I'm asking (it does require webdevelopment knowledge)

Let's say your website works with AJAX responses. You send JavaScript file to user's browser, which is a mini-engine, it sends request to your PHP server-side file. PHP answers with JSON. Your JavaScript file understands it and "does it". The question is, how would I prevent, someone who decides to nibble around my JavaScript file to go to http://example.com/donkey.php?getPost=x, and then make his/her own JavaScript file where they would make requests they weren't allowed to be made. For example, use my donkey.php and create identical website, because they technically can ask anything from database, that I ask as well.

Now turn this over to real life applications. How would I prevent someone sending same queries to the server, using their own program?7

Dammit, I really need to know. But I don't know how to explain it so you'd understand, I don't know what's the part, that you don't get.