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


n00b mySQL question :D





n0obie4life
lol. another one.

Okay. Let's say, this table called php_users.

in there, there's

user_pass
user_name
user_id
user_bleh
user_blah
user_die
user_heh_heh
user_heh_lol
user_heh_blah

So, I wanna use a mySQL query, to select all of the fields which have user_heh_

Note that I cannot do

Code:
SELECT user_heh_heh, user_heh_lol, user_heh_blah


as heh, lol, and blah can be ANYTHING.
a_n_d_y
Could you describe more? I need example of data of the table...
n0obie4life
a_n_d_y wrote:
Could you describe more? I need example of data of the table...


I did give an example Confused

Table name - php_users

In php_users, contains

user_pass
user_name
user_id
user_bleh
user_blah
user_die
user_heh_heh
user_heh_lol
user_heh_blah

"_heh", "_lol", "_blah" can be anything.

How would I get all the user_heh_<something> fields through mySQL
a_n_d_y
Code:
$res = mysql_query("SHOW FIELDS FROM php_users");
while ($r=mysql_fetch_array($res))
{
  if (ereg("user_heh_", $r[Field]))
   {
     $fields[]=$r[Field];
   }
}

So you have array with all filds like user_heh_<something>
n0obie4life
Right, can I not use arrays to do it (I'm horrible at it Laughing)

I was thinking something like

SELECT * FROM php_users LIKE user_heh_

won't work Sad
a_n_d_y
n0obie4life wrote:
Right, can I not use arrays to do it (I'm horrible at it Laughing)

I was thinking something like

SELECT * FROM php_users LIKE user_heh_

won't work Sad
Laughing Laughing Laughing
select * from ... like ...
You can select only values no field names Wink
But I didn`t understand where is the problem using arrays?
n0obie4life
Well, I don't know how to use it Embarassed

So, how would I echo it?
a_n_d_y
n0obie4life wrote:
Well, I don't know how to use it Embarassed

So, how would I echo it?

Code:

$res = mysql_query("SHOW FIELDS FROM php_users");
while ($r=mysql_fetch_array($res))
{
  if (ereg("user_heh_", $r[Field]))
   {
     $fields[]=$r[Field];
   }
}
 for ($i=0;$i<count($fields);$i++)
{
echo $fields[$i];
}

OR
Code:

$res = mysql_query("SHOW FIELDS FROM php_users");
while ($r=mysql_fetch_array($res))
{
  if (ereg("user_heh_", $r[Field]))
   {
     echo $r[Field];
   }
}
n0obie4life
yippie. Thanks.

I'll leave this thread open for more suggestions on how to do it (if there's any). But ATM, I'll use that.
Laz
I'm not to sure what you mean so I will just write a suggestion.
Oh wait I get what you mean sorry I re read what you wrote.
Ok.....
First of all You will need to include your config.php
Quote:

<?
include("config.php");
?>


And then to get the info from you tables.
Instead of using the above include we will put it in with the rest of the stuff

Quote:
<?php
include("config.php");

// The actual connection. DO NOT EDIT THESE

// the query view code.
$find = mysql_query("select * from DB_TABLE");

// getting all the info
$f=mysql_fetch_array($find);

$some=$f["some"];
$field=$f["field"];
$name=$f["name"];

Echo "$some <br> $field <br> $name ";

?>

I think thats what you mean kind of?
a_n_d_y
Laz wrote:

And then to get the info from you tables.
Instead of using the above include we will put it in with the rest of the stuff

Quote:
<?php
include("config.php");

// The actual connection. DO NOT EDIT THESE

// the query view code.
$find = mysql_query("select * from DB_TABLE");

// getting all the info
$f=mysql_fetch_array($find);

$some=$f["some"];
$field=$f["field"];
$name=$f["name"];

Echo "$some <br> $field <br> $name ";

?>

I think thats what you mean kind of?
But you can`t see field name here Wink
Related topics
PHP/MySQL question
quick mysql question
DBI.pm & DBD::mysql
Mysql question!
The last foolish PHP/MySQL Question of the Year....
MySQL Question
N00b Java Question
mySQL question....
newbie MySQL question
PHP MySQL Question
mySQL question
mySQL question N2 - Indexing
statement MySQL question
Newbie PHP/MySQL question
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.