FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to selecting this from a mysql table ?





Philip
I have a table user's right like this

user Can_Kick Can_Down Can_Push

Philip 1 1 0
Rudy 0 1 1
HexKid 1 0 1
Mathiaus 1 1 1

how to use sql statement for getting a query like this

Code:
Select ... from user where user='Philip'

Row1
Philip
1
1
0

Code:
Select ... from user where user='HexKid'

Row1
Philip
1
0
0
hexkid
Your sql statements look ok.
I don't understand what you want Sad

To do a query to a MySQL database in PHP I usually do
Code:
<?php
$con = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('connect: ' . mysql_error());
if (!mysql_select_db(DB_DATA)) die('select db: ' . mysql_error);
$usr = mysql_real_escape_string('Philip');
$sql = "select user, Can_Kick, Can_Down, Can_Push from user where user='$usr'";
$res = mysql_query($sql) or die('query: ' . mysql_error());
while ($row = mysql_fetch_row($res)) { // could be any other mysql_fetch_*()
  // deal with $row
}
mysql_free_result($res);
mysql_close($con);
?>


Oh! I never give the same name to a table and one of its columns.
Philip
i know2x, it's hard to understand.
i mean ussualy selecting data by coloumn,
now i want to selecting data by row,

ussually we selecting data become
user Can_Kick Can_Down Can_Push
Philip 1 1 0
Rudy 0 1 1
HexKid 1 0 1
Mathiaus 1 1 1

i want after selecting the data, the view of query be

Row1 Row2
User Philip
Can_Kick 1
Can_Down 1
Can_Push 0
hexkid
Philip wrote:
i know2x, it's hard to understand.
i mean ussualy selecting data by coloumn,
now i want to selecting data by row,

ussually we selecting data become
user Can_Kick Can_Down Can_Push
Philip 1 1 0
Rudy 0 1 1
HexKid 1 0 1
Mathiaus 1 1 1

i want after selecting the data, the view of query be

Row1 Row2
User Philip
Can_Kick 1
Can_Down 1
Can_Push 0


I don't think you can do that directly with MySQL. You can, however, display the data any way you like
Code:
<?php
$con = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('connect: ' . mysql_error());
if (!mysql_select_db(DB_DATA)) die('select db: ' . mysql_error);
$usr = mysql_real_escape_string('Philip');
$sql = "select user, Can_Kick, Can_Down, Can_Push from user where user='$usr'";
$res = mysql_query($sql) or die('query: ' . mysql_error());
while ($row = mysql_fetch_assoc($res)) {
  ### for each record print a <table>
  echo '<table>';
  foreach ($row as $col=>$val) {
    ### with different <tr>s for each column in the DB
    echo '<tr><td></b>', $col, '</b></td><td>', $val, '</td></tr>';
  }
  echo '<table>';
}
mysql_free_result($res);
mysql_close($con);
?>
Philip
thanks, but i already found a easy way Razz

like this way
Code:
   while ($i < mysql_num_fields($query))
   {
      $data_var[strtoupper(mysql_field_name($query, $i))]=$row[$i];
      $i++;
   }


thanks ^__^
Related topics
E-Cards with PHP & MySQL
HTTP AUTH with PHP and mySQL
mysql table keyword search
Working with Excel, PHP & MySQL. Any Ideas
SELECTing from MySQL with PHP
Can't create mySQL table
Reading MySQL values in reverse
Export and Import Mysql Table
Developing a Login System with PHP and MySQL
PHP/MySQL challenge, take it if you dare
Data Mining From tables and then insert into MySQL
Deleting duplicate rows in mysql
a new mysql table...
Subtrat values to a mysql table script
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.