apotterdd Posted July 18, 2008 Share Posted July 18, 2008 I can't seem to find one that explains the process thoroughly where it's understandable. Tried searching the web for SELECT COUNT and came up with squat. Anyone know of a good tutorials place? Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/ Share on other sites More sharing options...
Barand Posted July 18, 2008 Share Posted July 18, 2008 ... the process ... What process? Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593208 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 An explanation of what each step does. Anyone can download a script and run it on their site but I want to learn exactly what it does so I can use it to implement it how I need. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593971 Share on other sites More sharing options...
Lodius2000 Posted July 19, 2008 Share Posted July 19, 2008 dunno about barand but im still lost on what the process is Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593981 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 like a code such as this $cxn = ("$host","$user","$password","$database"); This statement establishes the connection to your database. Stuff like that. I don't want a bunch of code and be told "Try this". I want to be able to understand the code and what it does. Is it clearer now? Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593984 Share on other sites More sharing options...
Lodius2000 Posted July 19, 2008 Share Posted July 19, 2008 you want a tutorial for php in general, that is what i am getting i suggest a book, but there is plenty on the web, try w3schools, though i found it hard to follow EDIT: still lost on what you mean by 'dividing columns' Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593986 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 Which is what I'm trying to avoid is the manuals that go like a 747 over my head with out really explaining what everything actually does in human speak. I'm trying to find one that will divide a query result in to a few columns and the ones I found weren't really explaining much if anything at all. And the one book that I do have only goes over the SELECT COUNT statement without really showing me all the things that it can do. I'll have to dive into one of my other books on my computer to see if it has anything like what I'm looking for. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593990 Share on other sites More sharing options...
Lodius2000 Posted July 19, 2008 Share Posted July 19, 2008 no offence man but you need a better book, there are plenty out there, learning php 5 by o'reilly is a good one, by the end of the chapter 7 you will know enough about the 4 main sql statements to get by I like books as opposed to the web because they become sort of an encyclopedia, that you know how its laid out and can have a reasonable expectation of what to expect on a given topic, where the web can be a great dictionary, "whats the function for...?" or it can expand on what the book has. but basically the tutorials i have found on the web are pretty fast and 747ish, like you said, where books seem to take their time and be very gradual Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593994 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 That book has it's qualities it's mostly for ecommerce but I'm diving into other things like make that database work for me instead of fight with me which has been the case lately. I do have that Learn php 5 book but haven't had the chance to sit down and give it a once over. Now that I've figured out my links problem I can actually get away from the site and get down to learning. Thanks Anita Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593997 Share on other sites More sharing options...
xtopolis Posted July 19, 2008 Share Posted July 19, 2008 <?php $sql = "SELECT * FROM table WHERE 1";//This is the same command you would run on mysql locally via the CLI $result = mysql_query($sql);//PHP sends the command to mysql for processing and assigns a pointer to the result of that query ?> -$result now contains a pointer to the result set (set meaning all ROWS that matched that query, in this case, ANY and ALL rows (WHERE 1)) Manipulating result? Common approaches: (display the results until the end ($result == false when MYSQL has no more rows that match the query) Tabular data <?php echo '<table>'; while ($row = mysql_fetch_array($result)) { echo '<tr>'; echo '<td>'.$row['columnName'].'</td><td>'.$row['anotherColumn'].'</td>'; echo '</tr>'; } echo '</table>'; ?> -In the while loop, the statement asks for the next row in mysql's result until that next $row == false (no more rows) -For each row, this while loop ouputs an HTML table row with 2 cells -These cells contain 2 of the columns' values for that row as they appear in the mysql table -When $row == false(mysql returns false for the pointer of $result), the while statement ends, and the table is closed. So how do you divide your data into columns? However you want really. The way the data is given to you is pretty static (you can manipulate the querys and while loops, but almost always you will ask mysql for something and it will give you an array with your answers (or rather a pointer to request the answer(s)). From there, it's up to you how it's displayed. Hope that kinda shines some light on the subject. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-593999 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 It does. Never thought about doing it that way. I just hate a ton of white space where a links section is concerned. Don't really want one link per line, looks awful. Thank you so much And thank you for the explanation I appreciate that. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594008 Share on other sites More sharing options...
xtopolis Posted July 19, 2008 Share Posted July 19, 2008 I don't know the extent of your page, but if you want to display things on one line, and it's a series of links for say.. navigation.. just use CSS <style type="text/css"> ul li { display: inline;} </style> <ul> <li>Link 1</li> <li>|</li> <li>Link 2</li> </ul> Output would be similar to: Link 1 | Link 2 (may need a little more manipulation to hide <ul> uglies. You could even build the UL above from a while loop of stuff from your database. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594019 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 I don't think it's a css thing. I'm pulling url's to other sites from my database and want them to go into 2 columns on the php page where the links will be displayed. And I've gone back to my original problem where it's only showing one link from each category and not all of them, again. Sometimes I think I'm too picky for my own good. But that is what I want to achieve. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594022 Share on other sites More sharing options...
xtopolis Posted July 19, 2008 Share Posted July 19, 2008 Links or pictures might give us a better idea of what you want. But if you think you've got it, no need. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594028 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 Here's my links page that I'm messing with. http://www.mddu.com/links2.php What I've done there just now isn't really what I want. I want to divide the query results by 3 so the links will show up in 3 columns. I know I have to count the data using SELECT COUNT() but not sure how to code the results to get it to do what I want it to do. The answer I found on this site http://answers.yahoo.com/question/index?qid=20070731082159AA072ak is close to what I want to achieve but it's really confusing me a lot. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594029 Share on other sites More sharing options...
xtopolis Posted July 19, 2008 Share Posted July 19, 2008 Well, if you don't mind using tables (since you probably won't have more than 100 links), you could use the php modulus thing to push things to the next row. It depends in what order you want links to be displayed, and if they have the titles like you have on the page in that link. php mod(%) example: <?php echo '<table>'; echo '<tr>'; echo '<th>Title</th><th>link</th><th>Description:</th>'; echo '</tr>'; echo '<tr>'; while($result = mysql_fetch_array($result)) { for($i=0;$i<15;$i++) { if(($i % 3) == 0 && $i != 0) { echo '</tr><tr>'; } echo '<td>'.$row['title'].'</td><td>'.$row['href'].'</td><td>'.$row['description'].'</td>'; }//for }//while echo '</tr>'; echo '</table>'; ?> I didn't test this one, but you can find modulus examples on the web. Basically it says "if the counter ($i) is divisible by 3 with no remainder/decimal points, output a </tr><tr> to move to the next row, otherwise do nothing in the for loop, and output the <td>s Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594031 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 I'm going to test that one out and check out the modulus examples. Thanks. Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594033 Share on other sites More sharing options...
Barand Posted July 19, 2008 Share Posted July 19, 2008 here's an example of three cols <?php mysql_connect('localhost'); mysql_select_db('jointute'); $sql = "SELECT pupil_name FROM pupil ORDER BY pupil_name"; $res = mysql_query($sql); $cols = 3; $k = 0; $rows = ceil(mysql_num_rows($res)/$cols); // how many in each column ? while ($row = mysql_fetch_row($res)) { if ($k % $rows == 0) { echo '<div style="float:left; margin: 0 20px;">'."\n"; // new DIV } echo $row[0], '<br />',"\n"; // print pupil name ++$k; if ($k % $rows == 0) { echo '</div>'."\n"; // end DIV when full } } if ($k % $rows != 0) echo '</div>'."\n"; // end last DIV if not ended already echo '<div style="clear:both" ></div>'."\n"; // clear floats ?> --> Adam Simms Gearge Wilson Mary Blake Allan Blair Henry Irving Mary Sheldon Anna Hamilton Jane Morrison Mary Whitehouse Anne Bailey John Patterson Michael Grove Anthony Bell John Tully Peter Adamson Caroline Freeman John Watson Peter Appleby David Powell John Williams Wayne Jones Emma Watson Margaret Norton William Smith Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594062 Share on other sites More sharing options...
apotterdd Posted July 19, 2008 Author Share Posted July 19, 2008 I got it to work. Now I just need to tweak it to what I need. Thanks! Link to comment https://forums.phpfreaks.com/topic/115390-solved-in-search-of-a-good-tutorial-on-dividing-columns/#findComment-594065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.