Jump to content

[SOLVED] It's been to long and lost please help with simple stuff


Attila

Recommended Posts

OK here is what I got.  I have created a data base already and I can connect to the database now I am trying to pull stuff out of the database and display it on a webpage.  For this example I am going to a php page that is a constant and it will always pull the same information.  Because I haven't done PHP in so long I am cheating and using the phpmyadmin to generate this code.

$sql = 'SELECT * FROM `a1863106_items`.`DDO Items` WHERE (`ID` LIKE \'%Gloves%\' OR `Item Name` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Specific Item Type` 
LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Item Dexcription` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Quest` LIKE CONVERT(_utf8 \'%
Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Quest Level` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Notes` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1)
COLLATE latin1_general_ci)'; 

 

From what I remember I need to count to see how many instances are found.  Then I want to be able to display those in a table.  In order to display them in a table I need to put the data I got from the table into an array and then echo that array inside my html and loop that till count = 0.

 

Sorry I know I am asking alot for someone to help out with this it has just been a year or so since I have messed with PHP and I do not remember how to do it.  Please help a tinker bot.

 

P.S.  The website I am making is cheesy in itself....I play DDO an online video game.  I want to put all the unique items into a data base so people can look to see what quest they need to do to get these items and so forth.

 

Thanks,

Attila

Link to comment
Share on other sites

The database contains information like this:

 

ID          Item Name              Item Type              Item Description......etc

1          Speed Gloves            Gloves                    Speed Gloves - Improves your speed by +1

2          Damage Gloves          Gloves                    Damage Gloves - Improves your damage By +1

etc

 

I would like to be able to search the databes for all gloves then show the person the gloves that are in the database minus the ID number in a clean looking table.  So each ID number

is a diferent item with diferent description.

 

Thanks,

Attila

Link to comment
Share on other sites

I think you're looking for:

<table>
<th>stuff</th><th>more stuff</th>

<?php
$result = mysql_query($sql);

while($row = mysql_fetch_array($result)) {
  echo '<tr>';
  echo '<td>Item info</td><td>'.$row['itemname'].'</td>';
  echo '</tr>';
}
?>
</table>

 

This will display a new row for each item until the result is empty (reaches the end of matches).

Note, make your row['alias'] match your table of course.

 

Boo DDO :P

Link to comment
Share on other sites

Thank you all for such quick replies.  This is where I am at now.

<?php

//Connect to the database all fields are good so far				
database_connect();

$sql = 'SELECT * FROM `a1863106_items`.`DDO Items` WHERE (`ID` LIKE \'%Gloves%\' OR `Item Name` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Specific Item Type`LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Item Dexcription` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Quest` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Quest Level` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1) COLLATE latin1_general_ci OR `Notes` LIKE CONVERT(_utf8 \'%Gloves%\' USING latin1)COLLATE latin1_general_ci)'; 


$result = mysql_query($sql);

while($row = mysql_fetch_array($result)) {
  		echo '<tr>';
  		echo '<td>Item info</td><td>'.$row['itemname'].'</td>';
  		echo '</tr>';
}
?>

 

I know this is not everything yet I just wanted to see if I can get it to work....I did change my database $row['itemname'] to itemname instead of Item Name.  But now I beleive my $sql queary is all messed up.  and I am also getting the following error and I beleive it is because of my $sql search.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/......../............/gloves.php on line 29

 

Thanks again all....I would rather be messing with this then playiing the game.

Attila

 

 

Link to comment
Share on other sites

Lololololol, don't change your database!

 

change the statement in the while to match your database!

 

So you might do something like this:

while($row = mysql_fetch_array($result)) {
  		echo '<tr>';
  		echo '<td>'.$row['Item Name'].'</td><td>'.$row['Item Type'].'</td><td>'.$row['Item Description'].'</td>';
  		echo '</tr>';
}

 

THAT IS ONLY ASSUMING THAT YOUR COLUMN NAMES ARE LIKE YOU STATED IN A PREVIOUS POST:

The database contains information like this:

 

ID          Item Name              Item Type              Item Description......etc

1          Speed Gloves            Gloves                    Speed Gloves - Improves your speed by +1

2          Damage Gloves          Gloves                    Damage Gloves - Improves your damage By +1

etc

Link to comment
Share on other sites

LMAO.....I hope I have given you a good laugh...I have fixed back what you pointed out.  Although I beleive where I am messing up now is my:

 

$sql = bla bla bla......from what I remember this is what I am looking for in the table.  In the exaple I have provided like gloves in each field.  Can you see what is wrong on that part?

 

Thanks so much,

Attila

Link to comment
Share on other sites

Try a simple query.  It's hard to tell without knowing your database layout.

 

$sql = "SELECT * FROM yourtablename WHERE 1";

-Change yourtablename to the name of your items table

 

Then:

 

while($row = mysql_fetch_array($result)) {

  echo '<tr>';

  echo '<td>'.$row['columname'].'</td>';

  echo '</tr>';

}

-Change 'columnname' to the name of ONE of your column names.  So if your column in the database was named ItemName, change it to $row['ItemName'].  or if you have an ID column , you could just do $row['ID'] to check and make sure it's working.

Link to comment
Share on other sites

Still no luck so lets try this.  Here is my database layout:

 

Database Name is: a1863106_items    (This is a free website with PHP and MYSQL sorry)

 

Field Type Null Default Comments

ID  int(11) No     

ItemName  text No     

ItemType  text No     

ItemDescription  text No     

Quest  text No     

QuestLevel  text No     

Notes  text No     

 

Here is the error I am getting:

 

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/a1863106/public_html/gloves.php on line 22

 

Here is the full coding on the page

 

<?
// start the session 
session_start();
ob_start();
include ('includes/AllFunctions.php');
header("Cache-control: private"); //IE 6 Fix 
?>
<title>DDO Items</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
  <tr> 
    <? include ('includes/header.php');
?>
  </tr>
  <tr> 
    <td height="500">
<?
//Connect to the database all fields are good so far				
database_connect();
$sql = "SELECT * FROM a1863106_items WHERE 1";
   while($row = mysql_fetch_array($result)) {
    	    echo '<tr>';
        	echo '<td>'.$row['ItemName'].'</td>';
        	echo '</tr>';
}
?>
</td>
  </tr>
    <td align="center" valign="bottom"><? include ('includes/footer.php')?>
   </td>
   </table>
</html>

 

 

Thank you so much for your help.

Attila

 

Link to comment
Share on other sites

You forgot to actually submit the query.

 

<?php
$sql = "SELECT * FROM items WHERE 1";
$result = mysql_query($sql);
?>

$result = mysql_query($sql);

Add that line lol.

 

And also, I changed the name from a1863106_items to items.  You don't use a database name, you use a TABLE name.  So whatever you called your table that has the columns, use that.

Link to comment
Share on other sites

OK I think I figured out my problem but I am not sure how to fix it.

 

My database name is DDO Items

 

If I use this script:

$sql = "SELECT * FROM DDO Items WHERE 1";
$result = mysql_query($sql) or die(mysql_error());

 

I get this error:

Table 'a1863106_items.DDO' doesn't exist

 

I know my problem is that the name of my database is DDO Items how do I keep this as a string to look in that table?  Or could I change my database name with phpmyadmin to ddoitems?  If so how do I do that?

 

Thanks for all your help.

Link to comment
Share on other sites

Thank you so much for all your help I got it to work....Now I am just working on the formating and I can hande that.  I realy do appreciate all your help.....My next undertaking will be a very simple PHP form but I have all my old data with a form already done hopefull I can get that to work.....

 

 

Thanks Again,

Attila

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.