1
Sikandar
Displaying data from a table?
  • 2005/5/25 16:54

  • Sikandar

  • Just popping in

  • Posts: 99

  • Since: 2005/5/19


Hi,
I am searching for a generic code of php which I can use to display data from a table. So I will create a block and the data will be displayed in the form of a table. For example

Table
Segment1, Segment2, Segment3, Segment4
A 23 233 324
B 11 22 66
.
.
.
F 2 0 1

Just 6 to 7 records in the screen. Well I have no idea to do this in PHP. As I have XOOPS portal running locally so would like to create a table and display data on the scree. Please guide me so I can use the same database connectivity as XOOPS is using and develop a code as I explained above.

Thanks

2
fo-fo
Re: Displaying data from a table?
  • 2005/5/27 21:01

  • fo-fo

  • Just popping in

  • Posts: 34

  • Since: 2005/4/13


try this:

<?php
global $xoopsDB, $xoopsUser;
if ($xoopsUser)
{
$lognom = $xoopsUser->uname();
}

$result = mysql_query("SELECT * FROM ".$xoopsDB->prefix("segments_table")." WHERE segment='yes'");
while($row = mysql_fetch_array($result))
{

$segment1 = mysql_result($result, "t_row1");
$segment2 = mysql_result($result, "t_row2");
$segment3 = mysql_result($result, "t_row3");

echo "<table border='1'>";
echo "<tr><th><FONT FACE=arial> segment1 </th> <th><FONT FACE=arial> segment2 </th> <th><FONT FACE=arial> segment3 </th></tr>";
echo "<tr><td>";
echo "<FONT SIZE=1>$segment1</FONT>";
echo "</td><td>";
echo "<FONT SIZE=1>$segment2</FONT>";
echo "</td><td>";
echo "<FONT SIZE=1>$segment3</FONT>";
echo "</td></tr>";
}
?>

3
Sikandar
Re: Displaying data from a table?
  • 2005/5/29 6:45

  • Sikandar

  • Just popping in

  • Posts: 99

  • Since: 2005/5/19


Hi,
I have created a block and pasted the following code with a change in your code "removing ." WHERE segment='yes'"" but it is not showing me any result. I also set content type to "PHP Script" but no gain.
I used the following table,

create table segments_table(segment1 varchar(2), segment2 varchar(2),segment3 varchar(2));

inserted values,

insert into segments_table values ('a','b','c');

It is not even showing the block?

Will really appreciate all of you in resolving my issues.

Thanks


<?php
global $xoopsDB, $xoopsUser;
echo $xoopsDB;

if ($xoopsUser)
{
$lognom = $xoopsUser->uname();
}

$result = mysql_query("SELECT * FROM ".$xoopsDB->prefix("segments_table") );
while($row = mysql_fetch_array($result))
{

$segment1 = mysql_result($result, "t_row1");
$segment2 = mysql_result($result, "t_row2");
$segment3 = mysql_result($result, "t_row3");

echo "<table border='1'>";
echo "<tr><th><FONT FACE=arial> segment1 </th> <th><FONT FACE=arial> segment2 </th> <th><FONT FACE=arial> segment3 </th></tr>";
echo "<tr><td>";
echo "<FONT SIZE=1>$segment1</FONT>";
echo "</td><td>";
echo "<FONT SIZE=1>$segment2</FONT>";
echo "</td><td>";
echo "<FONT SIZE=1>$segment3</FONT>";
echo "</td></tr>";
}
?>

4
fo-fo
Re: Displaying data from a table?
  • 2005/5/29 12:49

  • fo-fo

  • Just popping in

  • Posts: 34

  • Since: 2005/4/13


$segment1 = mysql_result($result, "segment1");
$segment2 = mysql_result($result, "segment2");
$segment3 = mysql_result($result, "segment3");

?

WHERE segment='yes'... this is your_row=something_you_want_to_select

5
Sikandar
Re: Displaying data from a table?
  • 2005/5/29 15:37

  • Sikandar

  • Just popping in

  • Posts: 99

  • Since: 2005/5/19


Hi,
I have inserted only 3 records and I want to display all 3 so no need to specify where at the moment. Yes you are right later I will use it but right now I just want an output.

I am also getting error,

Parse error: syntax error, unexpected '<' in c:\apache\Apache\htdocs\html\class\xoopsblock.php(146) : eval()'d code on line 1


Thanks

6
Sikandar
Re: Displaying data from a table?
  • 2005/6/7 5:00

  • Sikandar

  • Just popping in

  • Posts: 99

  • Since: 2005/5/19


Hi All,
I am still unable to resolve my issue. Well let me write my requirement again in a more simple way,

Say I have a table "mytable" having one field "myfield" and the table contains only one record. I want to show this one record in the XOOPS block on the main page. Please guide me how to do this?

Thanks

7
Sikandar
Re: Displaying data from a table?
  • 2005/6/8 17:57

  • Sikandar

  • Just popping in

  • Posts: 99

  • Since: 2005/5/19


Pl let me know if I have to post/move this requirement in any other forum?

Login

Who's Online

167 user(s) are online (101 user(s) are browsing Support Forums)


Members: 0


Guests: 167


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits