LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2010, 02:54 PM   #16
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910

Quote:
Originally Posted by PehJota View Post
Well hopefully people write code that doesn't run horizontally forever... I personally find that well formatted code with indentation (not so much color coding) is far easier to read than the browser rendering of regular formatted HTML (which culls whitespace in text).
Totally. But you can achieve the same result w/ code
tags. All the PHP-tag offers over and above is colour; plus
the stupid sideways scrolling.

And - you may or may not have noticed - but yours and eoc92866
snippets both run off the page even if there's not much code
in them.

Even http://www.linuxquestions.org/questi...4/#post4142530 made it run off the side.

Cheers,
Tink

Last edited by Tinkster; 10-28-2010 at 02:55 PM.
 
Old 10-28-2010, 05:08 PM   #17
eoc92866
LQ Newbie
 
Registered: Oct 2010
Posts: 24

Original Poster
Rep: Reputation: 0
another gentleman assisted me and recommended this method...
PHP Code:
        foreach ($assoc_array as $row
over...
PHP Code:
      for ($i=0$i<=count($assoc_array); $i++) 
the foreach loop populated the fields in php.

does the recommendation for the undefined offset and index exist here?
 
Old 10-28-2010, 05:52 PM   #18
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Something like this
Code:
<html><head><title>MySQL Table Viewer</title></head><body>
<?php
$db_host = 'x.x.x.x';
$db_user = 'username';
$db_pwd = 'password';

$database = 'database';
$table = 'tableName';

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 name, help, folder, department FROM ${table}");
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);
?>
</body></html>
is cleaner, more secure, and almost certainly going to be more
efficient than what you're currently doing. While I understand
the rationale behind "code reuse" it pains me to see what you're
trying to do there.

At the end of the day (if your project is going to grow) you'd be
even better off using something like Smarty, and an object-oriented
approach to the whole problem, simply because it's easier to maintain
and harder to break.


Cheers,
Tink
 
Old 11-02-2010, 11:02 AM   #19
eoc92866
LQ Newbie
 
Registered: Oct 2010
Posts: 24

Original Poster
Rep: Reputation: 0
much appreciated to all.

thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash variable parsing! bashprog501 Programming 13 03-10-2011 08:34 PM
Parsing columns in bash seb357 Linux - Newbie 9 09-28-2009 02:40 PM
PHP not parsing snares Linux - Server 2 02-11-2009 11:17 PM
PHP Parsing ToothlessRebel Programming 20 10-25-2006 07:35 PM
php not parsing chens_83 Linux - General 9 02-19-2003 04:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration