473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

put ids into array from mysql query

201 100+
hello -

i'm trying to pull this query from the ids that are displayed on the page from another query.

it runs but it limits the result sets only returning one record instead of 2 that are for the query.

the first query can have many id's and the 2nd query can have many to the first.

the only way i can get the id is from assigning a variable to the posted id record set.

my main objective is to create an array from the id's in the first query to pull the data for the second query.

could u provide an example of storing an array of ids and accessing them for the 2nd qry? i've googled, but found some similar nothing useful.

i would post code but limit is 20 lines.

thanks in advance for your help!
Aug 30 '10 #1
18 3133
Dormilich
8,658 Expert Mod 8TB
not sure if I understood it correctly, but here are some (hopefully) helpful links:
PDO - fetchAll()
MySQLi - fetch_all()
Aug 30 '10 #2
would be great if you can exemplify what exactly your need is.
Aug 31 '10 #3
wizardry
201 100+
thanks for your response.

ok here is a moch of what im trying to accomplish.
Expand|Select|Wrap|Line Numbers
  1. //primary query
  2.  
  3. mysql_select_db($database_example, $example);
  4. $qry_user = "select id, name, img from users"
  5. $query_user = sprintf("%s LIMIT %d, %d", $query_user, $startRow_user, $maxRows_query_user);
  6. $user = mysql_query($query_limit_user, $example) or die(mysql_error());
  7. $row_user = mysql_fetch_assoc($user);
  8.  
  9. // sub query
  10.  
  11. mysql_select_db($database_notes, $notes);
  12. $query_notes = "select notes, id, idfk, name, dates from notes where idfk="$NId" order by dates desc";
  13. $query_limit_notes = sprintf("%s LIMIT %d, %d", $query_notes, $startRow_notes, $maxRows_notes);
  14. $notes = mysql_query($query_limit_notes, $notes) or die(mysql_error());
  15. $row_notes = mysql_fetch_assoc($notes);
  16.  
  17.  
ok here is my html moch of what im trying to accomplish.

Expand|Select|Wrap|Line Numbers
  1. <!-- 
  2. this is the layout for the first query
  3.  
  4. -->
  5. <table border="2" align="center" width="50%" cellpadding="5" cellspacing="5">
  6.     <?php do { ?>     
  7.     <tr>
  8.     <td valign="top" align="center"><?php echo $row_user['name']; ?><br /><img src="<?php echo $row_user['img']; ?>" height="120" width="120"/>    
  9. // i assign the id to a php variable to pull the second record query record set
  10.  
  11. $TNum = $row_user['Id'];
  12.  
  13.             //echo $TNum; // for debugging only
  14.             ?></td>
  15.             </tr>
  16.  
  17.  
  18. // second layout for second query
  19.  
  20. <?php 
  21.  
  22. // create array of name ID[$i] for record sets
  23.  
  24.     $TNum_Id=$_POST['TNum'];
  25.  
  26.     for($i=0;$i<count($TNum_Id);$i++) {
  27.  
  28.     //echo $i;
  29.  
  30.     $NId=$TNum_Id[$i]; 
  31.  
  32.  
  33. $result = $result = @mysql_query($query_notes, $notes) or die (mysql_error()) ;          
  34.  
  35.         $num = $totalRows_notes ; // get row count
  36.  
  37.         $thumbcols = 2 ; // column count
  38.  
  39.         // create the columns based on row count 5 columns per row
  40.         $thumbrows = 1+ round($num / $thumbcols);
  41.  
  42.         // check record set for values
  43.  
  44.         if(!empty($num)) {
  45.  
  46.     } // closing of record count
  47.  
  48. //create function for table layout
  49.     function display_table() {
  50.  
  51.         // create global variables
  52.         global $num, $result, $thumbrows, $thumbcols ; 
  53.  
  54.         // for loop for row counter
  55.         for ($r=1; $r<=$thumbrows; $r++) {
  56.  
  57.          echo '<tr>' ;
  58.  
  59.             // for loop for the columns
  60.             for ($c=1; $c<=$thumbcols; $c++) {
  61.  
  62.             echo '<td align="center" valign="top">';    
  63.  
  64.             // get array from the query
  65.  
  66.             $row = @mysql_fetch_array($result) ;
  67.  
  68.             $Id = $row['idfk'] ;
  69.             $Name = $row['name'] ;
  70.             $notes = $row['notes'] ;
  71.  
  72.             // check to see if path is not null
  73.  
  74.             if (!empty($Name)) {
  75.             echo "$Date"; echo "<br />";    
  76.             echo "$Name"; echo "<br />" ; echo "$Id"; // for debugging
  77.  
  78.             } // closing path
  79.  
  80.                 else {
  81.                     echo '&nbsp;' ;
  82.                 } //closing space
  83.                  echo '</td>' ;
  84.             } // closing the rows loop
  85.             echo '</tr>' ;
  86.         } //closing the row loop
  87.     } // closing the outer loop
  88.  
  89.     // display the table
  90.          display_table() ; 
  91.  
  92.           }
  93.       ?>
  94.  
  95. <?php     } while ($row_user = mysql_fetch_assoc($user));?>
  96.             </table>
  97.  
  98.  

the way the db design is 1=>8 on user / notes

what im trying to do is grab the id from user store it in a variable to pull if any records that match the sub query, else just show the user record.

thanks in advance for your help!
Aug 31 '10 #4
Lets do it step by step,

First some changes in your primary query. Please take a backup of your file and put this and run it. It should give some output and exit. Copy that output and paste here (to this forum). Put your backup file in place again.

Expand|Select|Wrap|Line Numbers
  1. //primary query
  2.  
  3. mysql_select_db($database_example, $example);
  4. $qry_user = "select id, name, img from users"
  5. $query_user = sprintf("%s LIMIT %d, %d", $qry_user, $startRow_user, $maxRows_query_user);
  6. echo  "SQL1 is: ".$query_user."<br>";
  7. $user = mysql_query($query_limit_user, $example) or die("Failed to run example query ".mysql_error());
  8. $row_user = mysql_fetch_assoc($user);
  9.  
  10. //debugging 1 start
  11. echo '<pre>debugging 1 start';
  12. while ($row_user_debugging = mysql_fetch_assoc($user)) {
  13.     print_r($row_user_debugging);
  14. }  
  15. echo '</pre>';
  16. //debugging 1 ends
  17.  
  18.  
  19. // sub query
  20.  
  21. mysql_select_db($database_notes, $notes);
  22. $query_notes = "select notes, id, idfk, name, dates from notes where idfk='$NId' order by dates desc";
  23. $query_limit_notes = sprintf("%s LIMIT %d, %d", $query_notes, $startRow_notes, $maxRows_notes);
  24. echo  "SQL2 is: ".$query_limit_notes."<br>";
  25. $notes = mysql_query($query_limit_notes, $notes) or die("Failed to run notes query ".mysql_error());
  26. $row_notes = mysql_fetch_assoc($notes);
  27.  
  28. //debugging 2 start
  29. echo '<pre>debugging 2 start';
  30. while ($row_user_debugging = mysql_fetch_assoc($user)) {
  31.     print_r($row_user_debugging);
  32. }  
  33. echo '</pre>';
  34. //debugging 2 ends
  35.  
  36.  
  37. exit;
  38.  
Aug 31 '10 #5
wizardry
201 100+
thanks for your response.

here is the output:


SQL1 is: select id, name, img from users

debugging 1 start

SQL2 is: select notes, id, idfk, name, dates from notes where idfk='' order by dates desc

debugging 2 start


I see that the key is not being captured into the array. I've used a debug echo on that on the first script.

thanks in advance for your help!
Aug 31 '10 #6
Lets concentrate on the first part only,

Take backup and Try this,

Expand|Select|Wrap|Line Numbers
  1. //primary query
  2. $db_selected = mysql_select_db($database_example, $example);
  3. if (!$db_selected) {
  4.     die ('Can not select DB : ' . mysql_error());
  5. }
  6.  
  7. echo "Limits |$startRow_user|, |$maxRows_query_user| <br>";
  8. $qry_user = "select id, name, img from users";
  9. echo  "Partial SQL1 is: ".$query_user."<br>";
  10. $query_user = sprintf("%s LIMIT %d, %d", $qry_user, $startRow_user, $maxRows_query_user);
  11.  
  12. echo  "Full SQL1 is: ".$query_user."<br>";
  13. $user = mysql_query($query_limit_user, $example) or die("Failed to run example query ".mysql_error());
  14. //$row_user = mysql_fetch_assoc($user);
  15.  
  16. //debugging 1 start
  17. echo '<pre>debugging 1 start';
  18. while ($row_user_debugging = mysql_fetch_assoc($user)) {
  19.     print_r($row_user_debugging);
  20. }  
  21. echo '</pre>';
  22. //debugging 1 ends
  23. exit;
  24.  
Sep 1 '10 #7
wizardry
201 100+
Limits |0|, |10|
Partial SQL1 is: select id, name, img from users
Full SQL1 is: select id, name, img from users

Expand|Select|Wrap|Line Numbers
  1. debugging 1 startArray
  2. (
  3.     [Name] => example
  4.     [Img] => ./example/demo/pictures/273930.jpg
  5.     [Id] => 10
  6.     )
  7. Array
  8. (
  9.     [Name] => example
  10.     [Img] => ./example/demo/pictures/273930.jpg
  11.     [Id] => 9
  12.     )
  13. Array
  14. (
  15.     [Name] => example
  16.     [Img] => ./example/demo/pictures/273930.jpg
  17.     [Id] => 8
  18.     )
Sep 1 '10 #8
Sorry for being too late,
I was occupied with some work.

Lets carry on,

Now please remove the exit command which I put in the first query (primary query). And put this debugging in place of second query. Dont forget to take a backup of your files.

Expand|Select|Wrap|Line Numbers
  1. // sub query
  2.  
  3. mysql_select_db($database_notes, $notes);
  4. echo "Limits |$startRow_notes|, |$maxRows_notes| <br>";
  5. $query_notes = "select notes, id, idfk, name, dates from notes where idfk="$NId" order by dates desc";
  6. echo  "Partial SQL1 is: ".$query_notes."<br>";
  7. $query_limit_notes = sprintf("%s LIMIT %d, %d", $query_notes, $startRow_notes, $maxRows_notes);
  8. echo  "Full SQL1 is: ".$query_limit_notes."<br>";
  9. $notes = mysql_query($query_limit_notes, $notes) or die(mysql_error());
  10. //$row_notes = mysql_fetch_assoc($notes);
  11.  
  12.  //debugging 1 start
  13.  echo '<pre>debugging 2 start';
  14.  while ($row_notes_debugging = mysql_fetch_assoc($notes)) {
  15.      print_r($row_notes_debugging);
  16.  }  
  17.  echo '</pre>';
  18.  //debugging 2 ends
  19.  exit; 
Give me the output.
Sep 5 '10 #9
wizardry
201 100+
ok this is what i have from the second part.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Limits |0|, |10|
  3. Partial SQL1 is: select id, name, img, dates from users order by Dates desc LIMIT 0, 10
  4. Full SQL1 is: select id, name, img from users LIMIT 0, 10
  5.  
  6. debugging 1 startArray
  7. (
  8.     [name] => example
  9.     [img] => ./example/demo/pictures/original/27393.jpg
  10.     [Id] => 10
  11.     [dates] => 2010-08-29 18:50:04
  12.     )
  13. Array
  14. (
  15.     [name] => example
  16.     [img] => ./example/demo/pictures/original/27393.jpg
  17.     [Id] => 9
  18.     [dates] => 2010-08-29 18:45:46
  19.     )
  20. Array
  21. (
  22.     [name] => example
  23.     [img] => ./example/demo/pictures/original/27393.jpg
  24.     [Id] => 8
  25.     [dates] => 2010-08-29 14:27:32
  26.     )
  27. Array
  28. (
  29.     [name] => example
  30.     [img] => ./example/demo/pictures/original/27393.jpg
  31.     [Id] => 7
  32.     [dates] => 2010-08-24 15:03:50
  33. )
  34. Array
  35. (
  36.     [name] => example
  37.     [img] => ./example/demo/pictures/original/27393.jpg
  38.     [Id] => 6
  39.     [dates] => 2010-08-24 14:59:17
  40. )
  41. Array
  42. (
  43.     [name] => example
  44.     [img] => ./example/demo/pictures/original/27393.jpg
  45.     [Id] => 3
  46.     [dates] => 2010-08-24 14:31:51
  47.   )
  48. Array
  49. (
  50.     [name] => example
  51.     [img] => ./example/demo/pictures/original/27393.jpg
  52.     [Id] => 2
  53.     [dates] => 2010-08-24 14:30:55
  54.     )
  55. Array
  56. (
  57.     [name] => example
  58.     [img] => ./example/demo/pictures/original/27393.jpg
  59.     [Id] => 1
  60.     [dates] => 2010-08-24 12:04:28
  61. )
  62.  
  63.  
  64. Limits |0|, |10|
  65. Partial SQL1 is: select notes, id, idfk, name, dates from notes order by dates desc
  66. Full SQL1 is: select notes, id, idfk, name, dates from notes order by dates desc LIMIT 0, 10
  67.  
  68. debugging 2 startArray
  69. (
  70.     [notes] => testing the status update comment schema
  71.     [dates] => 2010-08-29 23:03:36
  72.     [idfk] => 10
  73.  
  74. )
  75. Array
  76. (
  77.     [notes] => testing the status update comment schema
  78.     [dates] => 2010-08-29 23:03:36
  79.     [idfk] => 10
  80. )
  81. Array
  82. (
  83.     [notes] => testing the status update comment schema
  84.     [dates] => 2010-08-29 23:03:36
  85.     [idfk] => 9
  86. )
  87. Array
  88. (
  89.     [notes] => testing the status update comment schema
  90.     [dates] => 2010-08-29 23:03:36
  91.     [idfk] => 9
  92. )
  93. Array
  94. (
  95.     [notes] => testing the status update comment schema
  96.     [dates] => 2010-08-29 23:03:36
  97.     [idfk] => 7 
  98. )
  99. Array
  100. (
  101.     [notes] => testing the status update comment schema
  102.     [dates] => 2010-08-29 23:03:36
  103.     [idfk] => 3
  104. )
  105. Array
  106. (
  107.     [notes] => testing the status update comment schema
  108.     [dates] => 2010-08-29 23:03:36
  109.     [idfk] => 1
  110. )
  111. Array
  112. (
  113.     [notes] => testing the status update comment schema
  114.     [dates] => 2010-08-29 23:03:36
  115.     [idfk] => 1
  116. )
  117.  
  118.  
thanks in advance for your help!
Sep 5 '10 #10
are you messing up with the SQL output? I am not getting exact debugg SQL command being executed. eg this SQL is lacking "where" clause
Partial SQL1 is: select notes, id, idfk, name, dates from notes order by dates desc

though I am sure it should have pasted it.
May you wanted to keep it secure(is it?).

Well lets move on, I see that you get 8 rows from first query result and 8 rows from second query.

Now, let me know how do you want to show these result on the screen? I would create code as per your representation.
Sep 6 '10 #11
I think I got what you need. See the output it gives, that should be the one you are willing for.

Try this (take backup before doing all this)

Expand|Select|Wrap|Line Numbers
  1. //primary query
  2.  
  3. $all_ids = array(); 
  4. $str_ids = "";
  5. mysql_select_db($database_example, $example);
  6. $qry_user = "select id, name, img from users";
  7. $query_user = sprintf("%s LIMIT %d, %d", $query_user, $startRow_user, $maxRows_query_user);
  8. $user = mysql_query($query_limit_user, $example) or die(mysql_error());
  9. //$row_user = mysql_fetch_assoc($user);
  10. while ($row_user = mysql_fetch_assoc($user)) {
  11.   $all_ids[] = $row_user['id']; //this is the array you want, 
  12.   //but you dont need to use this much memory resources by creating array, you can use simple string to do this
  13.   $str_ids .= $row_user['id'].','; //add a comma
  14. }  
  15. //remove last comma eg from 2,4,5,6,7,
  16. $str_ids = (substr($str_ids,-1) == ',') ? substr($str_ids, 0, -1) : $str_ids;
  17.  
  18. //now create the second query with these ids
  19. $query_notes = "select notes, id, idfk, name, dates from notes where idfk in ($str_ids) order by dates desc";
  20. $query_limit_notes = sprintf("%s LIMIT %d, %d", $query_notes, $startRow_notes, $maxRows_notes);
  21. $notes = mysql_query($query_limit_notes) or die(mysql_error());
  22. //$row_notes = mysql_fetch_assoc($notes);
  23.  
  24.  //debugging 1 start
  25.  echo '<pre>debugging 2 start';
  26.  while ($row_notes = mysql_fetch_assoc($notes)) {
  27.      print_r($row_notes_debugging);
  28.  }  
  29.  echo '</pre>';
  30.  //debugging 2 ends
  31.  exit; 
Sep 6 '10 #12
wizardry
201 100+
thanks for your responses.

that was my error. but it should be as you have it where fkid = $id.

i had to remove it because it was not being feed into the string to query the second qry. i removed it to show that it does work for debugging.

thanks for your help! I just got up need to enjoy a couple cups of java, then i will post my results!
Sep 6 '10 #13
wizardry
201 100+
ok that does do what i want it to do, sorry for the late response. trying to incorporate this query method into my html table layout in php.

what im trying to do is group them by fkid with the user id in php.

example:
Expand|Select|Wrap|Line Numbers
  1. # debugging 1 startArray
  2. # (
  3. #     [name] => example
  4. #     [img] => ./example/demo/pictures/original/27393.jpg
  5. #     [Id] => 10
  6. #     [dates] => 2010-08-29 18:50:04
  7. #     )
  8. # debugging 2 startArray
  9. # (
  10. #     [notes] => testing the notes
  11. #     [dates] => 2010-08-29 23:03:36
  12. #     [idfk] => 10
  13. #  
  14. # )
  15. # Array
  16. # (
  17. #     [notes] => testing the notes
  18. #     [dates] => 2010-08-29 23:03:36
  19. #     [idfk] => 10
  20. # )
  21.  
  22.  
as in the example the parent query will be first then the child query will be right below it. then the next parent and child if any.

could you show me an example on how to display the results using this method. if needed i can post my current method.

thanks in advance for your help.
Sep 6 '10 #14
Expand|Select|Wrap|Line Numbers
  1. first query
  2. while loop(row)
  3. {
  4.    print here row
  5.    second query
  6.    while loop(row_child)
  7.    {
  8.      print here row_child
  9.    }
  10. }
Sep 7 '10 #15
Dormilich
8,658 Expert Mod 8TB
@pradeep: that’s not very efficient (though it works). less overhead is used when working with prepared statements:
- get all IDs with first query (1st query result array)
- make a prepared statement for the second query
- execute/fetch it for each of the IDs from the first query (result array)
Sep 7 '10 #16
Agree.

Even more efficient is what I gave before this.
Get all Ids with first SQL into array.
Create second query and use all ids from first in this query. Store into multidimensional array2.

Hence only Two DB querires.

Now, use loop to get things from array.
Sep 7 '10 #17
wizardry
201 100+
thanks for your responses. I will post both my method and your method latter.
Sep 7 '10 #18
wizardry
201 100+
ok i was able to get it working, however its not setting the $str_ids in this loop.

i've echo $str_ids after the - comma string and the comma is not being removed.

here is the output:
Expand|Select|Wrap|Line Numbers
  1. 10,11,12,5,6,7,8,1,2
  2.  
  3.  
  4.  
any insight is helpful, thanks in advance for your help!


here is my code:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $all_ids = array();
  3. $str_ids = "";
  4.  
  5. // first parent query
  6. $maxRows_sourceType = 10;
  7. $pageNum_sourceType = 0;
  8. if (isset($_GET['pageNum_sourceType'])) {
  9.   $pageNum_sourceType = $_GET['pageNum_sourceType'];
  10. }
  11. $startRow_sourceType = $pageNum_sourceType * $maxRows_sourceType;
  12.  
  13. mysql_select_db($database_Comments, $Comments);
  14. $query_sourceType = "SELECT c.Name, h.Path, h.Default, h.Id as hId, j.Id as Id, j.type, j.Dates, k.comment FROM aswebinfo as c right join asmanyalbums as e on ( c.UIdFk=e.UserId ) right join asalbums as f on ( e.AlbumId=f.Id ) right join astitle as g on ( f.Id=g.AlbumId ) right join asdata as h on ( g.Id=TitleId ) right join asstatusupdate as j on ( c.UIdFk=j.UIdFk) right join asstatusdata as k on (k.SFk=j.Id) WHERE f.Default='Y' and h.Default='Y' and c.UIdFk = any (select FriendId from asfriends where UIdFk0=1) order by Dates desc";
  15. $query_limit_sourceType = sprintf("%s LIMIT %d, %d", $query_sourceType, $startRow_sourceType, $maxRows_sourceType);
  16. $sourceType = mysql_query($query_limit_sourceType, $Comments) or die(mysql_error());
  17. $row_sourceType = mysql_fetch_assoc($sourceType);
  18.  
  19. if (isset($_GET['totalRows_sourceType'])) {
  20.   $totalRows_sourceType = $_GET['totalRows_sourceType'];
  21. } else {
  22.   $all_sourceType = mysql_query($query_sourceType);
  23.   $totalRows_sourceType = mysql_num_rows($all_sourceType);
  24. }
  25. $totalPages_sourceType = ceil($totalRows_sourceType/$maxRows_sourceType)-1;
  26.  
  27. // add the array
  28. while ($row_source = mysql_fetch_assoc($sourceType)) {
  29.  
  30.     $all_ids[] = $row_source['Id'];
  31.  
  32.     $str_ids .= $row_source['Id'].',';
  33.  
  34.  }
  35.  
  36.         // remove the array
  37.      $str_ids = (substr($str_ids,-1) == ',') ? substr($str_ids, 0, -1) : $str_ids;
  38.  
  39. //second child query
  40.     $maxRows_sourceComments = 10;
  41. $pageNum_sourceComments = 0;
  42. if (isset($_GET['pageNum_sourceComments'])) {
  43.   $pageNum_sourceComments = $_GET['pageNum_sourceComments'];
  44. }
  45. $startRow_sourceComments = $pageNum_sourceComments * $maxRows_sourceComments;
  46.  
  47. mysql_select_db($database_Comments, $Comments);
  48. $query_sourceComments = "select a.memo, a.date as Date, b.SFk, c.Name, g.Path  from ascomments as a  right join asmanystatusupdate as b  on a.Id=b.CFk, aswebinfo as c right join asmanyalbums as d on ( c.UIdFk=d.UserId ) right join asalbums as e on ( d.AlbumId=e.Id ) right join astitle as f on ( e.Id=f.AlbumId ) right join asdata as g on ( f.Id=g.TitleId ) where c.UIdFk=any(select friendid from asfriends where UIdFk0='1') and e.Default='Y' and g.Default='Y' and b.SFk in ($str_ids) order by date desc";
  49. $query_limit_sourceComments = sprintf("%s LIMIT %d, %d", $query_sourceComments, $startRow_sourceComments, $maxRows_sourceComments);
  50. $sourceComments = mysql_query($query_limit_sourceComments, $Comments) or die(mysql_error());
  51. $row_sourceComments = mysql_fetch_assoc($sourceComments);
  52.  
  53. if (isset($_GET['totalRows_sourceComments'])) {
  54.   $totalRows_sourceComments = $_GET['totalRows_sourceComments'];
  55. } else {
  56.   $all_sourceComments = mysql_query($query_sourceComments);
  57.   $totalRows_sourceComments = mysql_num_rows($all_sourceComments);
  58. }
  59. $totalPages_sourceComments = ceil($totalRows_sourceComments/$maxRows_sourceComments)-1;
  60.  
  61.  
  62.  
  63. $resultComments = @mysql_query($query_sourceComments, $Comments);
  64. $numComments = @mysql_num_rows($resultComments);
  65.  
  66.  
  67. $result = @mysql_query($query_sourceType, $Comments);
  68.  
  69. $num = @mysql_num_rows($result);
  70.  
  71. // column count for parent
  72.     $thumbcols = 1;
  73.  
  74.         // column count for parent query
  75.     $thumbrows = 1+ round($num / $thumbcols);
  76.  
  77.             // column count for child query    $thumbrowsComments = 1+ round($numComments/$thumbcols);
  78.  
  79.             // header
  80.             print '<br />';
  81.             print '<table align="center" width="500" border="2" cellpadding="0" cellspacing="0">';
  82.  
  83.             if (!empty($num)) {
  84.                 print '<tr><td colspan="3" align="center"><strong>Returned Num of Record Sets: ' .$num. ' and comments count' .$numComments. '</strong></td></tr>';    
  85.  
  86.             }
  87.  
  88.     // table layout for parent query        function display_table() {
  89.  
  90. // global variables
  91. global $num, $result, $thumbrows, $thumbcols, $resultComments, $numComments, $thumbrowsComments ;
  92.  
  93. // row count for parent
  94.  for ($r=1; $r<=$thumbrows; $r++) {
  95.  
  96.      // print table row
  97.          print '<tr>';
  98.  
  99. //format the columns
  100. for ($c=1; $c<=$thumbcols; $c++) {
  101.  
  102. print '<td align="center" valign="top">';
  103.  
  104.     $row = @mysql_fetch_array($result);
  105.  
  106.     $Id = $row['Id'];
  107.     $Path = $row['Path'];
  108.     $Name = $row['Name'];
  109.     $Type = $row['Type'];
  110.         $Dates = $row['Dates'];
  111.     $Comment = $row['Comment'];
  112.  
  113. // test if not empty show record sets            
  114.     if (!empty($Id)) {
  115.  
  116.                             // print output from parent query
  117.  
  118.                                     echo "$Name";
  119.                                     echo "<br />";
  120.                                     echo "&nbsp;";
  121.                             echo '<img src="' ."$Path". '" height="120" width="120" />'; 
  122.                                     echo "&nbsp;";
  123.                                     echo "<br />";
  124.  
  125.                                     // grab type dates comment and format for there column
  126.  
  127.                                     echo '<td valign="top" align="center">'; 
  128.                                     echo "$Type"; echo '&nbsp;&nbsp;'; echo "$Dates"; echo '<br />';echo '<br />';echo '<br />';
  129.                                     echo "$Comment"; echo '</td>';
  130.                                     echo '<td>'; echo "$Id"; echo '</td>';
  131.                                     echo '<td>'; echo "$str_ids"; echo '</td>';
  132.             } // closing the $id loop
  133.  
  134.                             // row count for second query
  135. for($i=1;$i<=$thumbrowsComments;$i++){                           // print new row
  136.                 print '<tr>';
  137.  
  138. // column count for second query
  139.         for ($g=1; $g<=$thumbcols; $g++) {
  140.                             print '<td align="center" valign="top">';
  141.  
  142.                             $com = @mysql_fetch_array($resultComments);
  143.  
  144.                             $Memo = $com['memo'];
  145.                             $Dates0 = $com['Date'];
  146.                             $SFk = $com['SFk'];
  147.                             $Name0 = $com['Name'];
  148.                             $Path0 = $com['Path'];
  149.  
  150.  
  151.     if (!empty($Memo)) {
  152. echo "$numComments";
  153.  
  154.                             echo "$Name0";
  155.                             echo "<br />";
  156.                             echo "&nbsp;";
  157.                             echo '<img src="' ."$Path0". '" height="120" width="120" />';
  158.                             echo "&nbsp;";
  159.                             echo "<br />";
  160.  
  161.                             // grab type comments and format the column
  162.  
  163.                                     echo '<td valign="top" align="center">';
  164.                                     echo "$Dates0";
  165.                                     echo "<br />";
  166.                                     echo "$Memo";
  167.                                     echo '</td>';
  168.                                     echo '<td>'; echo "$SFk"; echo '</td>';
  169.                             } // closing the $sfk loop
  170.  
  171.                                                 else {
  172.                                                         print '&nbsp;&nbsp;';
  173.                                                     }
  174.                             print '</td>'; //closing the table data
  175.                         } //closing the rows
  176.                             print '</tr>';
  177.              } // closing the outter loop
  178.             //} //closing fk id loop
  179.                             print '</td>'; //closing the table data
  180.                 } //closing the rows
  181.                             print '</tr>';    
  182.             } // closing the outter loop
  183.  
  184.     } // closing the main loop
  185.  
  186.                 // call the main table
  187.             display_table() ;
  188.                 print '</table>';
  189.  
  190.  
  191. ?>
  192.  
  193.  
  194.  
Sep 16 '10 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: joemyre | last post by:
Hi everyone, What I'm trying to do is take php variables i got from user input, and pass them as the MySQL query terms. $query = "select * from ident where ".$searchtype1."=".$searchterm1."";...
0
by: Murphy | last post by:
I am currently migrating a db from SQL Server & MySQL and ? (front end yet to be decided upon) As I familiarise myself with MySQL populating tables etc can be quite clumbersome. After reading the...
2
by: laredotornado | last post by:
Hello, Using PHP 4 and MySQL 4, how would I write a function such that it takes a valid MySQL query, and a column on which to order the query, and return a new query ordered by that column? ...
0
by: taras.di | last post by:
Hi everyone, I've come across an extremely strange problem. The exact same query in both mysql command line client, and mysql query browser gives entirely different results. I was hoping someone...
2
by: Flic | last post by:
Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice:...
2
by: stmfc | last post by:
i have a problem with user creation for mysql db i think the problem stems from string style. GRANT ALL ON newDB.* TO 'test'@'localhost' IDENTIFIED BY 'test'; i am...
10
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer...
4
by: John | last post by:
Hello All, Can someone help me with a problem I am having? I have a form which has a multi-select list where the user can select more than one company name from a list and I need to pass those...
1
by: pretzelboy | last post by:
Hi, I last wrote software 13years ago in the pascal, dbase, clipper days. I have recently built a Ubuntu Box and with C++ (and help from the web) setup a serial barcode reader program using Mysql...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.