Jump to content

beginner mysql query with php help


knowram

Recommended Posts

I am not sure if this question belongs in the mysql section or not so if it does forgive me.

 

Say I have the following table:

PID Action Hardware Set Dialplan

14 I         test-HS-2 test2

14 I         test-HS-1         TestDialpl

14 I         test-HS-2 test3

 

I would like to select the second time PID = 14.

 

 

Link to comment
https://forums.phpfreaks.com/topic/196507-beginner-mysql-query-with-php-help/
Share on other sites

So I know I can do the following. Say the Table name is Tabs

$Tab = mysql_query("SELECT * from `Tabs` WHERE PID = '14'");

$Tab = mysql_fetch_array($Tab, MYSQL_ASSOC);

 

And it will return first row in the table where PID = 14

or

$result = mysql_query("select * from `Tabs` where  PID = '14' ") or
						die ("nope");

while ($Tab = mysql_fetch_array($result, MYSQL_ASSOC)){
print_r($Tab);
}

and that will print all rows where PID = 14.

 

What I am trying to do is just get the content of the second row where PID = 14.

if i understand, you need this line

 

14  I            test-HS-1          TestDialpl

 

You might want to try

 

$Tab = mysql_query("SELECT * from `Tabs` WHERE PID = '14' AND hardware = ' test-HS-1'");

 

But this is not a good approach. You need a unique ID in your table.. Like

 

+---++---++-------++------------+

| ID | PID| |action|  |Hardware|

+---++---++-------++------------+

|  1 | 14  |

|  2 | 14  |

|  3 | 14  |

|  4 | 14  |

 

And so on

 

Then $Tab = mysql_query("SELECT * from `Tabs` WHERE ID = '2'");

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.