Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old October 17th, 2002, 05:56 PM
gagnonconsulting gagnonconsulting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 gagnonconsulting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Trouble with Matt's Column Sorting Tutorial

I am getting the following error when using the tutorial example that Matt provided on how to sort a retrieved table by column headings:

Fatal error: Call to undefined function: mysql_fetch_assoc()

Other functions, such as mysql_fetch_array() work. Is this a version problem, or am I missing something?

Thanks,
Rich

Reply With Quote
  #2  
Old October 17th, 2002, 06:01 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Trouble with Matt's Column Sorting Tutorial

mysql_fetch_assoc was introduced in 4.0.3....

Reply With Quote
  #3  
Old October 15th, 2003, 07:27 PM
redneck_kiwi redneck_kiwi is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Talladega, AL 35160
Posts: 24 redneck_kiwi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

I am working this same issue and have a similar problem. My database is called custinfo and the table involved is custcont.
Output from DESC custcont is:

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| datecon | date | YES | | NULL | |
| ieipoc | varchar(25) | YES | | NULL | |
| custpoc | varchar(50) | YES | | NULL | |
| custname | varchar(25) | YES | | NULL | |
| subject | varchar(50) | YES | | NULL | |
| comment | varchar(250) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
7 rows in set (0.15 sec)

My code:

php Code:
Original - php Code
  1.  
  2. <HTML>
  3. <TITLE>Contact Database</TITLE>
  4. <BODY BGCOLOR="white" TEXT="black" LINK="blue" VLINK="violet" BACKGROUND="images/gray.gif">
  5. <CENTER><H1>Customer Contact Database</H1></CENTER>
  6.  
  7. <?php
  8. /* Set up to allow the user to sort the columns at will. The code following
  9. will allow this capacity */
  10. $default_sort = 'datecon';
  11. $allowed_order = array ('datecon', 'ieipoc', 'custpoc', 'custname');
  12.  
  13. /* If order is not set, or it is not in the allowed list, then set it to a defau
  14. lt value, otherwise, set it to what was passed in. */
  15. if (!isset ($_GET['order']) ||
  16.         !in_array ($_GET['order'], $allowed_order))
  17.         {
  18.                 $order = $default_sort;
  19.         }
  20. else
  21.         {
  22.                 $order = $_GET['order'];
  23.         }
  24.  
  25. /* Connect to the DB */
  26. mysql_connect ('localhost','root','********');
  27. mysql_select_db ('custinfo');
  28.  
  29. /* Construct and run our query */
  30. $query = "SELECT * FROM custcont ORDER BY $order";
  31. $result = mysql_query ($query);
  32.  
  33. /* Make sure data was retrieved */
  34. $numrows = mysql_num_rows($result);
  35.  
  36. if ($numrows ==0)
  37. {
  38.         echo "<CENTER>No Data Was Retrieved!</CENTER>";
  39.         exit;
  40. }
  41.  
  42. /* Now, grab the first row and start the table */
  43. $row = mysql_fetch_assoc($result);
  44.  
  45. echo '<TABLE BORDER=1>n';
  46. echo '<TR>n';
  47. foreach ($row as $heading=>$column)
  48. {
  49.         /* Check if the heading is in our allowed_order array
  50.                 If it is, hyperlink it so that we can order by
  51.                 this column. */
  52.         echo '<TD><B>';
  53.         if (in_array ($heading, $allowed_order))
  54.         {
  55.                 echo "<a href="{$_SERVER['PHP_SELF']}?order=$heading">$heading
  56. </A>";
  57.         }
  58.         else
  59.         {
  60.                 echo $heading;
  61.         }
  62.         echo '</B></TD>n';
  63. }
  64. echo '</TR>n';
  65.  
  66. /* Reset the $result set back to the first row and display the data */
  67. mysql_data_seek($result, 0);
  68. while ($row = mysql_fetch_assoc($result))
  69. {
  70.         echo '<TR>n';
  71.         foreach ($row as $column)
  72.         {
  73.                 echo '<TD>$column</TD>n';
  74.         }
  75.         echo '</TR>n';
  76. }
  77. echo '</TABLE>n';
  78.  
  79. /* End sort code */
  80.  
  81. ?>
  82.  
  83. <CENTER>
  84. <B><A TARGET="_blank" HREF="http://localhost/input.php">Input New Record
  85. </A></B>
  86. <B><A TARGET="_blank" HREF="http://localhost/search.php">Search For Reco
  87. rd</A></B>
  88. </CENTER>
  89. <P></P>
  90. <P></P>
  91. <BR></BR>
  92. <P><CENTER><I><B><H6>Copyright (c) 2003 by International Enterprises, Inc. All r
  93. ights reserved</H6></B></I></CENTER></P>
  94. </HTML>
  95.  


Output from this page is WEIRD:
IEI Face to Face Contact Database

IEI Customer Contact Database

n
n idn dateconn ieipocn custpocn custnamen subjectn commentn
n
n $columnn $columnn $columnn $columnn $columnn $columnn
$columnn
n

n

Input New Record Search For Record

Copyright (c) 2003 by International Enterprises, Inc. All rights reserved


Anyone have a clue to loan as to why the actual data is not displayed?

Thanks

rk

Reply With Quote
  #4  
Old October 15th, 2003, 08:39 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Trouble with Matt's Column Sorting Tutorial

Try changing this line
'<TD>$column</TD>n';
so it would look like this:
'<TD>'.$column'.</TD>n';

Reply With Quote
  #5  
Old October 16th, 2003, 11:23 AM
redneck_kiwi redneck_kiwi is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Talladega, AL 35160
Posts: 24 redneck_kiwi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

Doh! That fixed it. I looked and looked and looked at the code and didn;t see that I had the variable within the ticks....ah well, thanks for the pointer!

On another issue with this code, HOW can I change the column name display? Instead of 'datecon', I would prefer 'Date of Contact'? Also, can I prevent certain columns from being displayed at all? Would this be done from within the select statement?

TIA

rk

Reply With Quote
  #6  
Old October 16th, 2003, 11:36 AM
gagnonconsulting gagnonconsulting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 gagnonconsulting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

Glad that helped. As far as column names, set them in the Select statement, like this:

$query = ("SELECT M.Firm, L.abrev Local, M.memberType Type, M.Name, M.Street, M.City, M.State, M.Zip, M.Phone, M.Ext, M.Fax, M.Email, M.WebURL"); $query .= (" FROM Member M, LocalAssn L");
$query .= (" WHERE M.LocalAssn_id=L.assn_id");

For instance, the word Local is substituted for the L.abrev column name in the results.

Rich

Reply With Quote
  #7  
Old October 16th, 2003, 11:41 AM
gagnonconsulting gagnonconsulting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 gagnonconsulting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

If it is in the select statement, it will print, so change your select statement from * (all) to the explicit columns you want returned, as in the previous post example.

Rich

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Trouble with Matt's Column Sorting Tutorial


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |