I want a linked image and then the name of the game afterwards linked

OK here just the sql is…
[php]

<?php // Connect to the database and the "games" table... $DB=mysqli_connect("10.0.0.2","****","*****","games"); // Check if the connection worked or failed... if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Connected to table, now run a query to pull all the game names... $results = mysqli_query($DB,"SELECT * FROM games"); while($row = mysqli_fetch_array($results)) { echo $row['name'] . "'s filename is: " . $row['file']; echo "
"; } // Close the connection which releases memory in the server... mysqli_close($DB); ?>

[/php]
Thought I neeed to change something.
Here are my errors:

Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it. in C:\xampp\htdocs*********\sqltest.php on line 14
Failed to connect to MySQL: No connection could be made because the target machine actively refused it.
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\kappaapps\sqltest.php on line 22

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\kappaapps\sqltest.php on line 24

Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\kappaapps\sqltest.php on line 30

IF i make host localhost intead of 10.0.0.2 which I need for family to access, I get only this:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs*********\sqltest.php on line 24

By post with the old, do you mean the glob table setup we had and this?

First, use “localhost” for your web address. So, dump the 10.0.0.2 and tell it localhost…

Remember, it’s a website. So, this PHP code is for your use, not the family’s!!!

They will need to use something like “http://10.0.0.2/games.php” to access the site.

But, the PHP code they do NOT see. That is on your server-side only.

So, make sure your user ID and password are correct.

Also, sometimes you have to use a port number such as “localhost:80” or “localhost:8080”.
(The second one is generally for Wamp users. The first for normal servers.)

One other thing. Do you have a firewall set up? If so, you may be blocking your server…

Let me know…

[php]

Untitled Document <?php
//  Connect to the database and the "games" table...
$DB=mysqli_connect("localhost", "games");

// Check if the connection worked or failed...
if (mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();

}

// Connected to table, now run a query to pull all the game names…
$results = mysqli_query($DB,“SELECT * FROM games”);

while($row = mysqli_fetch_array($results)) {
echo $row[‘name’] . "'s filename is: " . $row[‘file’];
echo “
”;
}

// Close the connection which releases memory in the server…
mysqli_close($DB);

?>

<?php // Start the table echo ""; // Get names of games from directory $dirname = "games/"; $games = glob($dirname."*.php"); // Now display 25 games with links for ($x=0; $x<=6; $x++) { echo ""; for ($y=0; $y<=6; $y++) { // Place each game inside a table's cell (Later on use CSS to make them fit nicely) echo ""; } echo ""; } echo "
"; // Check if there is a file. If not, leave an empty cell, if there is one, display it if (isset($games[$y+$x*7])){ // First get the name without the extension $temp = substr(trim($games[$y+$x*7]), 0, -4); // Set up HREF to point to HTML code for the entire table cell (any click inside will go there) echo ""; // Display the picture (inside the anchor to the html file) echo "
"; // Show the name of the game echo "".basename($temp).""; // And, end the link! echo "
"; } else { // Display whatever for a blank cell echo "New Game Coming Soon!"; } // End the cell no matter if empty or not echo "
"; ?> [/php]

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in \gamesnew.php on line 23

No firewall…

Okay, I forgot to mention one other issue. You have name and file in the database.
the file is the name of the SWF you want to load. It should also be the name of the JPG file.

Just the name without any extensions… With the SWF and JPG files having the same name,
and that name stored, it makes the code much easier…

Fixed that…still have error, but didn’t think it’d change the error.

So, it’s connecting to the database now?

Place this command after the $results = line and see if it displays a count.

[php]
// Connected to table, now run a query to pull all the game names…
$results = mysqli_query($DB,“SELECT * FROM games”);
$rowcount=mysqli_num_rows($result);
echo $rowcount . " Games were found!";
die();
[/php]
This will tell you how many games or records it found and then stop. If it shows the games you loaded
into the table, then we are good up to there.

Ooops, sorry, forgot an “S” in line 4…
[php]

//  Connected to table, now run a query to pull all the game names... 
$results = mysqli_query($DB,"SELECT * FROM games");
$rowcount=mysqli_num_rows($results);
echo $rowcount . " Games were found!";
die();

[/php]

Did I get the name of the TABLE correct? Was it “games”? Caps DO count !

Everything is right and I used second code sample, just as you said… I get this

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in gamesnew.php on line 69
Games were found!

Well, something is wrong with the database connection. So we have to alter the query and see what the error really is:

[php]
// Connected to table, now run a query to pull all the game names…
if (!$results = mysqli_query($DB,“SELECT * FROM games”)) {
die(“There was an error while running query: " . mysqli_error($DB);
}
$rowcount=mysqli_num_rows($results);
echo $rowcount . " Games were found!”;
die();
if(!$result = $db->query($sql)){
die(‘There was an error running the query [’ . $db->error . ‘]’);
}
[/php]
Was going to do that error check anyways eventually…

SORRY SORRY! Tired Type’n again… So, use this one…

[php]
// Connected to table, now run a query to pull all the game names…
if (!$results = mysqli_query($DB,“SELECT * FROM games”)) {
die(“There was an error while running query: " . mysqli_error($DB);
}
$rowcount=mysqli_num_rows($results);
echo $rowcount . " Games were found!”;
die();
[/php]

Oh, man, bedtime! Forgot a ) ! ! !
[php]

  //  Connected to table, now run a query to pull all the game names... 
  if (!$results = mysqli_query($DB,"SELECT * FROM games")) {
    die("There was an error while running query: " . mysqli_error($DB));
    }
  $rowcount=mysqli_num_rows($results);
  echo $rowcount . " Games were found!";
  die();

[/php]

[php]<?php

//  Connect to the database and the "games" table...
$DB=mysqli_connect("localhost","root","kappa","kappaapps");

// Check if the connection worked or failed...
if (mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();

}

//  Connected to table, now run a query to pull all the game names... 
    if (!$results = mysqli_query($DB,"SELECT * FROM games")) {
      die("There was an error while running query: " . mysqli_error($DB));
      }
    $rowcount=mysqli_num_rows($results);
    echo $rowcount . " Games were found!";
    die();

while($row = mysqli_fetch_array($results)) {
echo $row[‘name’] . "'s filename is: " . $row[‘file’];
echo “
”;
}

// Close the connection which releases memory in the server…
mysqli_close($DB);

?>[/php]
2 Games were found! :slight_smile:

Good night! I feel like I’ve learned today, a lot.

Well, hold on… I have one more post before bed for you… a couple minutes…

Ok! Holding on. BTW I moved die down after the bracket after while, and now it shows the game’s filename is: thing!! Yeah!!! Was just messing around with it to learn.

[php]

<?php // Get names of games from the database // Connect to the database and the "games" table... $DB=mysqli_connect("localhost","****","*****","games"); // Check if the connection worked or failed... if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Connected to table, now run a query to pull all the game names... if (!$results = mysqli_query($DB,"SELECT * FROM games LIMIT 0, 25")) { die("There was an error while running query: " . mysqli_error($DB)); } // No errors, now show game count... $rowcount = mysqli_num_rows($results); echo $rowcount . " Games were found!
"; // Now show up to 25 games... (May be less if at end of game table entries) while($row = mysqli_fetch_array($results)) { echo $row['name'] . "'s filename is: " . $row['file'] . "
"; } // Close the connection which releases memory in the server... mysqli_close($DB); ?>

[/php]
This should show the games now… And, next would be placing them into the table cells…

2 Games were found!
Beventlaed’s filename is: beventlaed
The Bravest Hunter’s filename is: bravesthunter

except it’s centered because of my css. Great! I’ll add the rest of my games I have so far to SQL, then cells and links/images I imagine will come with cells. Maybe I’ll even figure out some of it myself tonight. :o ;D

Well, here is the basics of it all. That’s why I said wait a bit. Too tired to continue. I am in New England, US and it is 1:15 AM and 7 AM comes quick! So, last post tonight… BTW, thanks for the Karma!

Now, the way that the data is pulled out has an error on it. I will try to sort it out tomorrow.
The changes form the GLOB version is that we loop thru the array of “games” resulting from the
query in the database. We display them one at a time one inside each table cell. Since you wanted
5x5, I set it up that way with two 0-4 FOR’s. 0-4 is five… The only thing I have to solve is how to
advance the $games[] array to the next one after displaying it. So, almost there… Well, then the
links and paginations… Lots of items covered during all this! Good luck… Tomorrow…

[php]

<?php // Connected to table, now run a query to pull all the game names... if (!$results = mysqli_query($DB,"SELECT * FROM games LIMIT 0, 25")) { die("There was an error while running query: " . mysqli_error($DB)); } // No errors, now show game count... $rowcount = mysqli_num_rows($results); echo $rowcount . " Games were found!
"; // Start the table (Border for now so we can see if it is working correctly...) echo ""; // Now show up to 25 games... while($games = mysqli_fetch_array($results)) { for ($x=0; $x<=4; $x++) { echo ""; for ($y=0; $y<=4; $y++) { // Place each game inside a table's cell (Later on use CSS to make them fit nicely) echo ""; } echo ""; } } echo "
"; // Check if there is a file. If not, leave an empty cell, if there is one, display it if (isset($games[])){ // First get the name without the extension echo $games['name'] . "'s filename is: " . $games['file'] . "
"; // Set up HREF to point to HTML code for the entire table cell (any click inside will go there) echo ""; // Display the picture (inside the anchor to the html file) echo "
"; // Show the name of the game echo "" . $games["name"] . ""; } else { // Display whatever for a blank cell echo "New Game Coming Soon!"; } // End the cell no matter if empty or not echo "
"; // Close the connection which releases memory in the server... mysqli_close($DB); ?>

[/php]
Note the new addition to the query ! I set it to start at record number 0 and take only the first 25 recs.
What this does is set us up for pagination. Later we will change the 0 to a page# and let the database
do the work of pulling the correct page of 25 games for us. No work on our end except telling MySQL to
start at the page number. Easy… (So, if you put in 30 games tonight, the first 25 should show up 4 now.)
Nite!

Ok, good night!

Yeah, the karma is the least I can do… lol. Get some sleep! I hope it’s okay that I reply after you head off, I figure this way, you can see once you get on, lol.

I fixed the error that at least I was getting by putting ‘’ in this line…

[php]if (isset($games[’’])){[/php] after some googling…

NOW what it does is tells me 24 games are found and then echos a table that is 5 (so the x is correct) by probably 50 or more ( y is bad ), I am SO not counting exactly the y height. Lol.

That was ALL I changed after adding, just so you know. :wink: Excited for pages…

Also, hey, I don’t want this to be a whole topic by any means, just a quick answer if you can give one. I have a chat application on my page…
[php][/php]

This is some javascript for it, sorry for asking, lol, but when content goes over the size of the box, it does autosroll down, but you are locked down. If you try and scroll up, it sends you back down immediately. Any idea of a quick fix? Still want autoscroll to bottom…

Sponsor our Newsletter | Privacy Policy | Terms of Service