Author Topic: Echo mysql data in marquee  (Read 1490 times)

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Echo mysql data in marquee
« on: October 08, 2011, 02:36:06 am »
Hey :) basically I would like to display some mysql data in a marquee

Here's my mysql database;

cydiapdt (database)
marquee (table)
Text (field)

And then I've inserted Test123 in Text :p

This is my current code but when I go onto the webpage it just shows array scrolling across

Code: [Select]
<div>
<marquee>
<?php
// Make a MySQL Connection
mysql_connect("*********""*********""******") or die(mysql_error());
mysql_select_db("cydiapdt") or die(mysql_error());

$query mysql_query("SELECT * FROM marquee") or die(mysql_error());
$row=mysql_fetch_assoc$query );
echo 
$row;
?>



</marquee>
</div>

Can anyone help :)!

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: Echo mysql data in marquee
« Reply #1 on: October 09, 2011, 07:06:03 am »
Bump >:(

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: Echo mysql data in marquee
« Reply #2 on: November 12, 2011, 08:37:01 pm »
sorry no one could help. but now i think ik the answer, if it's still helpful. even if not, someone else may have a similar problem.

try print_r($row); instead of echo $row; because it's an array, and echo doesnt print arrays. also, you could use a foreach loop, but for this circumstance, its fine to use print_r();

Ginger

  • Dev Team Member
  • Hero Member
  • *****
  • Posts: 610
  • Reputation: 6
    • PwnDevTeam!
  • Computers: Forgot model but Dell Inspirion Tower (6gb ram, Quad core, 1tb hdd, 1gb graphics)
  • iDevices: iPod Touch 4G 8GB And iPod Nano 1G 1Gb
Re: Echo mysql data in marquee
« Reply #3 on: November 15, 2011, 03:42:41 pm »
Thanks I will try soon :) +1

d3nn

  • Full Member
  • ***
  • Posts: 169
  • Reputation: 3
    • 7h31310g
  • Badges:
  • Computers: 1 old server, and a new asus
  • iDevices: ipod touch 4g on ios 5
Re: Echo mysql data in marquee
« Reply #4 on: September 12, 2012, 06:38:15 pm »
Hey :) basically I would like to display some mysql data in a marquee

Here's my mysql database;

cydiapdt (database)
marquee (table)
Text (field)

And then I've inserted Test123 in Text :p

This is my current code but when I go onto the webpage it just shows array scrolling across

Code: [Select]
<div>
<marquee>
<?php
// Make a MySQL Connection
mysql_connect("*********""*********""******") or die(mysql_error());
mysql_select_db("cydiapdt") or die(mysql_error());

$query mysql_query("SELECT * FROM marquee") or die(mysql_error());
$row=mysql_fetch_assoc$query );
echo 
$row;
?>



</marquee>
</div>

Can anyone help :)!
Did a3miral's solution fix it?

If not try doing mysql_fetch_array to show the exact row that you want to display.

Code: [Select]
<div>
<marquee>
<?php
// Make a MySQL Connection
mysql_connect("*********""*********""******") or die(mysql_error());
mysql_select_db("cydiapdt") or die(mysql_error());

$query mysql_query("SELECT * FROM marquee") or die(mysql_error());
$row mysql_fetch_array$query );
$therow $row['whateverrowyouwant'];
echo 
$therow;

Liked this post? Come visit my blog!

http://7h31310g.blogspot.com

Don't like seeing ads? Click here to register!

Almost

  • Full Member
  • ***
  • Posts: 128
  • Reputation: 20
Re: Echo mysql data in marquee
« Reply #5 on: September 13, 2012, 06:02:25 am »
You get an array as a result. An array is a list of values, denoted by keys. For example:

Code: [Select]
<?php
$myArray 
= Array(
   
'name' => 'Ginger',
   
'profession' => 'pentester',
   
'age' => 20
);
?>


You can now access each value through these keys:
Code: [Select]
<?php
echo $myArray['name']; // Results in Ginger
echo $myArray['age']; // Results in 20
?>


So in your example, you can first print it using print_r or var_dump. Then, when you know the structure of your array, you can access it as shown (and as done by d3nn at the end of his post)
Code: [Select]
<div>
<marquee>
<?php
$connection 
mysql_connect("*********""*********""******");
if ( !
$connection ) {
throw new Exception'Failed to make a connection: '.mysql_error() );
}

$success mysql_select_db("cydiapdt")
if ( !
$success ) {
throw new Exception'Failed to select the database: '.mysql_error() );
}

$result mysql_query("SELECT * FROM marquee LIMIT 1");
if ( !
result ) {
throw new Exception'Failed to query the database: '.mysql_error() );
}

$row mysql_fetch_assoc$query );
echo 
htmlspecialchars($row['columnname']);
?>

</marquee>
</div>

Use htmlspecialchars() to prevent XSS!