techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old Jul 9, 2012, 10:02 PM   #1
Wozzer
500 Posts
 
Join Date: Jun 2008
Location: England
Posts: 990 (0.55/day)
Thanks: 166
Thanked 76 Times in 72 Posts
Send a message via MSN to Wozzer

System Specs

Extracting data from relational databases

Hi,

New to phpmyadmin, PHP, MySQL, etc - so please excuse me if the answer to the question is simple.

I've built a database using XAMPP called "evidence db". Within that database, I have a table called "m cases". This table has 11 columns.

I currently have the following code:
Code:
<html>
<head>
<title>Search data</title>
</head>
<body>
<table>
  <tr>
    <td align="center">EMPLOYEES DATA</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <tr>
        <td>Case ID</td>
      </tr>
<?

mysql_connect("localhost","root","");//database connection
mysql_select_db("evidence db");
				
$order = "SELECT * FROM m cases";
				
$result = mysql_query($order);	

while($data = mysql_fetch_row($result)){
$field1= $row["Case ID"];
  echo("$field1");
}
?>
    </table>
  </td>
</tr>
</table>
</body>
</html>
Error:
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\helloworld.php on line 25

Thanks in advanced.

PS - If anyone can recommend PHP/Phpmyadmin tutorials - i'd be interested in reading them.
Wozzer is offline  
Reply With Quote
Old Jul 9, 2012, 11:17 PM   #2
digibucc
3500 Posts
 
digibucc's Avatar
 
Join Date: May 2009
Location: In the mountains :) Adirondacks in NY (US)
Posts: 3,709 (2.49/day)
Thanks: 4,547
Thanked 1,449 Times in 1,040 Posts

System Specs

i recommend checking out http://www.phpfreaks.com/, not to advert other forums but they are dedicated to php coding and will likely get you solved much faster than here, unless one of the few gurus happen to post.

also, all you ever need other than a forum is the manual pages
http://php.net/manual/en/index.php

more specifically, the man page for mysql_fetch_row(), here:
http://php.net/manual/en/function.mysql-fetch-row.php

as it says, it is recommend with current php versions to use a different mysql extension entirely, with good reason. you may want to consider that. good luck.
__________________

Donate to TPU TeamSpeak Server

TPU TS: ts21.gameservers.com:9207

PSN / XBL / Steam = digibucc | Origin / BF3 = digibuc
digibucc is offline  
Reply With Quote
The Following User Says Thank You to digibucc For This Useful Post:
Old Jul 11, 2012, 01:34 PM   #3
Jizzler
2000 Posts
 
Jizzler's Avatar
 
Join Date: Aug 2007
Location: Geneva, FL, USA
Posts: 3,010 (1.41/day)
Thanks: 567
Thanked 606 Times in 487 Posts

System Specs

There's a space in that table name, so it needs to be escaped with backticks.

Code:
$order = "SELECT * FROM `m cases`";
In the future, don't put spaces in your table or column names. Use an underscore (m_cases) or go camel case (mCases).

Also, if you're just starting to learn, I'd suggest going with their PDO interface instead of the database specific functions.

http://www.php.net/pdo

Been meaning to put together a small intro to PDO for the forum, with the recent rise in PHP/database questions. Maybe I'll get around to doing it now that I said I would...
Jizzler is offline  
Reply With Quote
The Following 2 Users Say Thank You to Jizzler For This Useful Post:
Old Jul 11, 2012, 09:56 PM   #4
Wozzer
500 Posts
 
Join Date: Jun 2008
Location: England
Posts: 990 (0.55/day)
Thanks: 166
Thanked 76 Times in 72 Posts
Send a message via MSN to Wozzer

System Specs

Did put the backticks and have also updated the DB name to have no spaces - still no luck. Will have a better look at it tomorrow. Thanks for the input.
Wozzer is offline  
Reply With Quote
Old Jul 12, 2012, 12:50 AM   #5
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,284 (4.27/day)
Thanks: 1,219
Thanked 2,789 Times in 1,801 Posts

System Specs

just FYI, technically evidence db is a schema and not a database.
Easy Rhino is offline  
Reply With Quote
The Following 2 Users Say Thank You to Easy Rhino For This Useful Post:
Old Jul 12, 2012, 09:45 PM   #6
Mindweaver
Moderato®™
 
Mindweaver's Avatar
 
Join Date: Apr 2009
Location: Statesville, NC
Posts: 3,887 (2.55/day)
Thanks: 4,379
Thanked 2,365 Times in 1,183 Posts

System Specs

You don't have a password setup for "root"? I would set a password or actually go one step further and change the "root" user id to something else completely, but that's just me.

EDIT: Nice catch Easy Rhino!
__________________
“As long as I feel the warmth from the sun and breathe precious air…. I must ask questions to feed the Mind!”

Battletag: Mindweaver#1523
Mindweaver is offline  
Crunching for Team TPU
Reply With Quote
Old Jul 12, 2012, 10:10 PM   #7
Aquinus
3500 Posts
 
Aquinus's Avatar
 
Join Date: Jan 2012
Location: Dover, New Hampshire, USA
Posts: 4,505 (8.87/day)
Thanks: 1,441
Thanked 1,423 Times in 1,063 Posts

System Specs

You need error checking, my friend.

Change this:
PHP Code:
mysql_connect("localhost","root","");//database connection
mysql_select_db("evidence db");
                
$order "SELECT * FROM m cases";
                
$result mysql_query($order); 
To this:
PHP Code:
$conn mysql_connect("localhost","root","");//database connection
if(!$conn) {
    throw new 
Exception('Unable to connect');
}

$dbname 'evidence db';
if(!
mysql_select_db($dbname)) {
    throw new 
Exception('Unable to use db: {$dbname}');
}
                
$order "SELECT * FROM `m cases`";
                
if(!
$result mysql_query($order$conn)) {
    throw new 
Exception("Query failed.\n".mysql_error($conn));

Since your table also has a space in it, you need to denote the table name using back ticks. It may allow double quotes for table names as well, but I don't recall (I use PostgreSQL too often.)

Quote:
Originally Posted by Wasley View Post
Error:
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\helloworld.php on line 25
Your query is throwing an error (mysql_query(), must be returning a non-object and the only non-object it returns is false on an error.) Try out the back-ticks, that probably will fix it.
PHP Code:
$order "SELECT * FROM `m cases`"
Lastly, the mysql functions you are using are deprecated. Look into MySQLi or ADODB.
__________________
MyHeat

Last edited by Aquinus; Jul 12, 2012 at 10:16 PM.
Aquinus is offline  
Crunching for Team TPU
Reply With Quote
Old Jul 14, 2012, 12:18 PM   #8
Wozzer
500 Posts
 
Join Date: Jun 2008
Location: England
Posts: 990 (0.55/day)
Thanks: 166
Thanked 76 Times in 72 Posts
Send a message via MSN to Wozzer

System Specs

Thanks for the input. It's now working

Wozzer is offline  
Reply With Quote
Old Jul 15, 2012, 08:53 PM   #9
Wozzer
500 Posts
 
Join Date: Jun 2008
Location: England
Posts: 990 (0.55/day)
Thanks: 166
Thanked 76 Times in 72 Posts
Send a message via MSN to Wozzer

System Specs

Has anyone ever had problems with dreamweaver displaying the page layout differently to that shown on a web browser?
Wozzer is offline  
Reply With Quote
Old Jul 15, 2012, 09:00 PM   #10
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts

System Specs

I haven't but that probably because I never used Dreamweaver.

Okay, I'm not trolling. I've noticed that in several IDE environments that what the IDE shows is not always the same as when it runs in a browser or as an application. For instance, working with WPF in VS2010, what is shown in the IDE is not always the same as when you run the app outside of the IDE.
Minor emulation differences I assume.

Best to check everything in its final resting place (like in a browser) than count on the display in the tools to be accurate.
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp
Kreij is offline  
Reply With Quote
Old Jul 15, 2012, 09:44 PM   #11
Aquinus
3500 Posts
 
Aquinus's Avatar
 
Join Date: Jan 2012
Location: Dover, New Hampshire, USA
Posts: 4,505 (8.87/day)
Thanks: 1,441
Thanked 1,423 Times in 1,063 Posts

System Specs

Dreamweaver has its own HTML render. You will find that with certain setting, they will look a little different between different browsers, be it Firefox, Chrome, IE, etc. When testing, you really should check all the different browsers that you're planning to support. That's the only way to make sure it works on all of them the way you have your HTML and CSS configured because two browsers might handle padding, margins, and borders differently depending on the settings.

My rule of thumb is: Don't use Dreamweaver.
__________________
MyHeat
Aquinus is offline  
Crunching for Team TPU
Reply With Quote
Old Jul 16, 2012, 05:34 PM   #12
Wozzer
500 Posts
 
Join Date: Jun 2008
Location: England
Posts: 990 (0.55/day)
Thanks: 166
Thanked 76 Times in 72 Posts
Send a message via MSN to Wozzer

System Specs

Just out of interest - What do you guys use?
Wozzer is offline  
Reply With Quote
Old Jul 16, 2012, 05:42 PM   #13
W1zzard
Benevolent Dictator
 
W1zzard's Avatar
 
Join Date: May 2004
Location: Stuttgart, Germany
Posts: 13,866 (4.17/day)
Thanks: 184
Thanked 10,448 Times in 3,216 Posts
Send a message via ICQ to W1zzard Send a message via AIM to W1zzard Send a message via MSN to W1zzard Send a message via Skype™ to W1zzard

System Specs

Quote:
Originally Posted by Wasley View Post
Just out of interest - What do you guys use?
i use dreamweaver for the rough layouting. any text editor (ultraedit in my case) + firefox firebug for the details

if you are asking what database: tpu uses mysql everywhere, memcached for caching
W1zzard is online now  
Reply With Quote
Old Jul 16, 2012, 06:57 PM   #14
digibucc
3500 Posts
 
digibucc's Avatar
 
Join Date: May 2009
Location: In the mountains :) Adirondacks in NY (US)
Posts: 3,709 (2.49/day)
Thanks: 4,547
Thanked 1,449 Times in 1,040 Posts

System Specs

i use jetbrains phpstorm. if i were to use a wysiwyg it would be dreamweaver, but i don't do much real layout work, and stick to coding.
__________________

Donate to TPU TeamSpeak Server

TPU TS: ts21.gameservers.com:9207

PSN / XBL / Steam = digibucc | Origin / BF3 = digibuc
digibucc is offline  
Reply With Quote
Old Jul 17, 2012, 02:48 AM   #15
Aquinus
3500 Posts
 
Aquinus's Avatar
 
Join Date: Jan 2012
Location: Dover, New Hampshire, USA
Posts: 4,505 (8.87/day)
Thanks: 1,441
Thanked 1,423 Times in 1,063 Posts

System Specs

I use vim to edit PHP, my database of choice is PostgreSQL. Even when I do layout, I usually write the CSS by hand and I use various browsers to test it. I prefer Chrome, but not everyone uses Chrome, so I keep Firefox and IE handy as the most commonly used.
__________________
MyHeat
Aquinus is offline  
Crunching for Team TPU
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting video BIOS from main BIOS WaroDaBeast Motherboards & Memory 6 Dec 25, 2011 12:40 AM
Online databases? <<Onafets>> Programming & Webmastering 2 Jan 3, 2011 07:59 AM
Extracting a swollen battery from a UPS twilyth General Hardware 8 Aug 10, 2010 07:48 PM
Extracting audio from youtube videos in Linux- Solution crazy pyro Linux / BSD / Mac OS X 9 Jul 31, 2009 05:55 PM
SQL Relational algebra new_rez Programming & Webmastering 2 Mar 18, 2008 06:02 PM


All times are GMT. The time now is 07:34 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts