Old 26-02-2008, 09:43   #1 (permalink)
Heka1
Senior Member
 
Join Date: Jul 2007
Posts: 179
Selecting a Intersecting number

Hey Everyone, I am still learning PHP and I have learned a lot these past few months and I am finally understanding it, but I am building a new system and I have ran into a PHP/MySQL Road block and I was hoping to get some help. First off I want to let you know that I have looked for tutorials online and I have not found any which I believe fits this topic, But I would be more then happy if someone had a tutorial I could use.

Problem:
I have a table full of data shown below and I am trying to get a Intersecting number from the table. I have tried selecting both the column and Row that I want to use and I am coming up short.

Code:
weight 1 2 3 4 100 9 8 7 6 120 8 7 6 5 130 7 6 5 4 140 6 5 4 3 150 5 4 3 2

As you Can see the red is highlighted, I would like to get this number and simple echo it out, this is basically a times table and im looking to get the answer. I am looking for a point in the right direction or a little help. Thanks in advance for any help that I could get.
__________________
XHTML, CSS, PHP, Flash Web Designer
www.Heka1.com
www.DrunkMobile.com/m
  Reply With Quote
Old 26-02-2008, 09:54   #2 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Can you have numbers as column names in MySQL? EDIT: Yes, apparently you can.

Anyway, if that were my table, I'd do the following:

PHP Code:
// Query needs to be SELECT column FROM table WHERE expression that identifies a row(s)
$result $db->query("SELECT 3 FROM table WHERE weight=130");

if(
$result->num_rows 0) {
  while(
$row $result->fetch_assoc()) {
    echo 
$row[3];
  }

That should return "5". Unless there are multiple rows where weight=130.
  Reply With Quote
Old 26-02-2008, 12:44   #3 (permalink)
Heka1
Senior Member
 
Join Date: Jul 2007
Posts: 179
Thanks pgo, That is what I am looking for, I guess I have just been working with it for a while and it was causing me to over think the problem. And on a side note I'm actually not using numbers as column names, it just made the most sense for a quick post.
__________________
XHTML, CSS, PHP, Flash Web Designer
www.Heka1.com
www.DrunkMobile.com/m
  Reply With Quote
Old 26-02-2008, 13:58   #4 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Ah, I see. Though you can use numbers as column names. I have no idea why anyone would want to, but it's possible - I even tested it.
  Reply With Quote
Reply



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

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8