Jump to content

Recommended Posts

Hi All,

I was hoping to recive some help.  I need a DB quiery for a sales DB we have, i have the code (below) and it works as intended.

 

<?php
$db_host = '';
$db_user = '';
$db_pwd = '';

$database = '';
$table = 'nexus_purchases';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

// sending query
$result = mysql_query("Select ps_name,ps_member,ps_custom_fields from nexus_purchases where ps_name like 'Varified Owner'");

if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>

 

 

The part i need help with is, this quirey returns,

 

returns.png

 

Now the app that deals with our club shop, (nexus) adds bits to the DB I.e (  a:2:{i:3;s:8:  ) 

 

So in the two feilds when buying club membership someone enters  x  hae and ST24

 

 

And nexus adds  a:2:{i:3;s:8:"X HAE";i:4;s:4:"ST24";} to the table in ps_custom_fields

 

What i would like to do is strip out everything not in quotes and get left with  "X HAE"  "ST24"

 

I hope someone could help me out,  Thanks in Advance.

 

Link to comment
https://forums.phpfreaks.com/topic/246919-mysql-quirey-string-maniplulation-help/
Share on other sites

Thanks for the Reply

Short answer no i didnt,

 

in our Car club you buy membership online using IP.Nexus,

(we have set up custom feilds in the package to allow users to input there car details) as we need them for the events and show, (every time there is one)

 

At the moment because of Nexus, we can not veiw the information they place in the feilds with out veiwing the invoices one by one,  300+ , no thanks

Although we have put in a feature request, Who knows when and if it will happen,

 

The idea was to quirey the Db for the infomation we need,  its just we dont want to see it the extra,

 

(some of our events admin, are not computer literate, and these excess parts of the feild will just confuse things. )

 

Thanks again.

The principle behind serialising the data is that you can unserialise it when you retrieve the data. a quick example of retrieveing the data in php and mysql is:

 

<?php
$result = mysql_query("Select ps_name,ps_member,ps_custom_fields from nexus_purchases where ps_name like 'Varified Owner'");
..... all of the standard stuff here

while($row = myql_fetch_array($result)
{
$ps_custom_fields_to_array = unserialize($row['ps_custom_fields']);
$ps_comma_seperated_string = implode(',',$ps_custom_fields_to_array);

// this will make $ps_comma_seperated_string look like X, HAE, ....
}

Thank you, This is exacly what i needed,

BUT....    lol

 

I get a syntax error on line 22,

Which is

<?php
$result = mysql_query("Select ps_name,ps_member,ps_custom_fields from nexus_purchases where ps_name like 'Varified Owner'");
..... all of the standard stuff here

while($row = myql_fetch_array($result)
{     (syntax error here)
$ps_custom_fields_to_array = unserialize($row['ps_custom_fields']);
$ps_comma_seperated_string = implode(',',$ps_custom_fields_to_array);

// this will make $ps_comma_seperated_string look like X, HAE, ....
}

 

Did i break it, lol

 

Thanks Again.

 

AyKay47: Thank you for your answer, but it was a lil over my head, :)

 

while($row = myql_fetch_array($result)
{     SYNTAX ERROR HERE 
$ps_custom_fields_to_array = unserialize($row['ps_custom_fields']);
$ps_comma_seperated_string = implode(',',$ps_custom_fields_to_array);

 

 

mySql

Oppsies,

Thanks

Thank you both of you,

 

The Syntax error has gone,  ) + the S, lol

 

But i fail, this is my first post

<?php
$db_host = '';
$db_user = '';
$db_pwd = '';

$database = '';
$table = 'nexus_purchases';

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

// sending query
$result = mysql_query("Select ps_name,ps_member,ps_custom_fields from nexus_purchases where ps_name like 'Varified Owner'");

if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);

echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";

    echo "</tr>\n";
}
mysql_free_result($result);
?>

 

This is your replies,

<?php
$result = mysql_query("Select ps_name,ps_member,ps_custom_fields from nexus_purchases where ps_name like 'Varified Owner'");
..... all of the standard stuff here

while($row = mysql_fetch_array($result))
{     (syntax error here)
$ps_custom_fields_to_array = unserialize($row['ps_custom_fields']);
$ps_comma_seperated_string = implode(',',$ps_custom_fields_to_array);

// this will make $ps_comma_seperated_string look like X, HAE, ....
}

 

 

Where do i put it?  i assumed i replaced the while in my code, with the while from your reply, But all i get is one cell thats empty?

 

Thank you so much guys(girls), i never would have got this, lol

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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