Jump to content

Recommended Posts

Hi, first of all, thanks to everyone who has helped me so far, I hope I am not too annoying spamming questions like a little nublet.

I am currently designing the infastructure for a set of sites I want to set up. Alot of it involves pulling data from the DB and displaying it (echo is the only way I assume?)



---- 1 -----

When echoing a long bit of text from the DB into a table is there a way to confine it somehow, the text just sprawls across horizontally and I want to contain it in a table e.t.c so it doesn't look scrappy ! Whether there is a simple table confine html solution or a different php echo solution I would love to know!

---- How do I do that?



----- 2 -----

Very similar to number 1, I have a page where privalged users can give other users announcement permmissions. Is there a way to pull all the usernames from a table and display them in a drop down form? I tried to but all the form has was a <option> Click me </option> for each variable on the menu so I couldn't figure out how to turn the respone from that unique option into a variable.
-
----- So how do I display and insert info into/from the DB for drop down forms?



----- 3 -------


Last one, how do I pull the oldest array from a table in the DB using a select query, when the only date records I have in the table for each array is from date("m/d/y").

------ How do I pull the oldest record from an array in the DB?




Any help would be awesome, I am really loving PHP just getting stuck here and there...
Link to comment
https://forums.phpfreaks.com/topic/10766-a-few-nublet-questions/
Share on other sites

1. I think something like this will wrap it up.
[code]<div style="width: 90%"> INFORMATION HERE </div>[/code]

2. Let's say you have an "id" field and a "username" field:
[code] echo '<select name="users">';

$query = mysql_query("SELECT id, username FROM users"):
while($r = mysql_fetch_row($query)) {
   echo '<option value="' . $r['id'] . '">' . $r['username'] . '</option>';
}

echo '</select>'[/code]

3. You can use "SELECT * FROM table ORDER BY date ASC LIMIT 1"
Link to comment
https://forums.phpfreaks.com/topic/10766-a-few-nublet-questions/#findComment-40243
Share on other sites

Hi poirot you have been most helpful.

1. The was just what it needed, now all the announcements are tucked tidily in the center :)

can check it out at www.lifenz.com/phppractice/index.php youll have to make an acc tho lol :)

2. Ok I have successfully got all the usernames to display in the form! wow learning so much!

3. SELECT * FROM table ORDER BY date ASC LIMIT 1" So setting ASC LIMIT to 1 will choose the oldest? and then how to do I turn what it fetches into a variable? Do I need to use a fetch array? .


Thanks.....
Link to comment
https://forums.phpfreaks.com/topic/10766-a-few-nublet-questions/#findComment-40428
Share on other sites

Glad to help [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

2. Maybe the field is not named 'username'? Did you try to open the HTML source and see what is in there?

3. Yes. You need to fetch it as usual to turn it into a variable.
Link to comment
https://forums.phpfreaks.com/topic/10766-a-few-nublet-questions/#findComment-40429
Share on other sites

[!--quoteo(post=378573:date=May 30 2006, 09:57 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 09:57 PM) [snapback]378573[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Glad to help [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

2. Maybe the field is not named 'username'? Did you try to open the HTML source and see what is in there?

3. Yes. You need to fetch it as usual to turn it into a variable.
[/quote]


Hi have been ticking away all day, managed to get number 2 going there was a simple field name era as you pointed out. I now have a system going where users can upload make "adventure journals" with text, (photos soon to be added). And I have a form that you select the user you want to views journals, it really is getting there! fantastic!

Still here are a few problems I havent been able to solve all day:



------------------
1. "You can use "SELECT * FROM table ORDER BY date ASC LIMIT 1"

On page one of viewing this users journals I want to have a table grid of say 4 each grid with a picture and title of the journal that they want to view.

So I want to select oder by date and then pick out the newest, 2nd newest, 3rd newest e.t.c automatically and assign a variable to each one. I don't really understand this ASC LIMIT 1 concept. So therefore when you view a users journals you see the newest ones on the front page of that section.




2. Related to 1. When the users clicks on the photo or JTITLE they want I need it to set a variable to set a variable to equal something, is there like an on mouse click function do this command? And would it be best to use a href and reload the page with a variable=something way, or is there a php button or something I can use loll... :/



3. Is there a way to clear the POST_DATA or make a variable equal nothing at the end of a page. I have found upon refreshing a page after clicking on a form which assigns post_data to variables, it uploads the previously posted data again! most annoying...

If there is a way I will use "<?php if ( isset($variable) ): ?>" statement to control whether to add data to the DB.

-----------

The questions never stop, I will keep tucking away at these tomorrow but any help would be great gets me out of the rut of brooding over a problem for hours on end :/

Thanks again and again poirot
Link to comment
https://forums.phpfreaks.com/topic/10766-a-few-nublet-questions/#findComment-40525
Share on other sites

SELECT * FROM table ORDER BY date ASC LIMIT 1

Let's break that down...

"SELECT" is the command
"*" means everything from the table
"FROM table" says which table to use
"ORDER BY date" says how we want the data ordered (this case by the field "date")
"ASC" means in ascending order (ie. A, B, C) opposite is DESC
"LIMIT 1" means only return one row of data

If you use LIMIT 10 then that'd return 10 rows of data but you'd need to set up a loop to read all of the rows.

If you want to only read the most recent 4 pieces of journal data then use something like this:

SELECT * FROM table ORDER BY date DESC LIMIT 4

To make it clickable try something like this:[code]$query=mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 4");
while ($fetch=mysql_fetch_array($query)) {
  echo '<a href="page'.$fetch['id'].'.php">Journal Page '.$fetch['id'].'</a>";
}[/code]That method will make actual links being those of page??.php (??=valud of "id" in the database) but if you want to pass the value to page.php replace the echo above with this:[code]  echo '<a href="page.php?p='.$fetch['id'].'">Journal Page '.$fetch['id'].'</a>";[/code]That will make something like this: page.php?=id (where "id" is the value)

Make sense?
Link to comment
https://forums.phpfreaks.com/topic/10766-a-few-nublet-questions/#findComment-40528
Share on other sites

Hi Yesideez, thanks very much for your reply, have followed your methods and have successfully got it working for the most part (as usual :P). The page is now displaying the 4 latest journals for that user and then sets a varaible jc=jtitle and reloads the page, which then shows the user the journal they choose!!! :D :D

For starters, I set the Jtitle to equal "1" so then when it carried over, jc=1 then on reentry of the script it hit the if(isset(jc)) section and displayed the journal. This worked fine when Jtitle was a number, but as soon as I changed it to say "My First Journal" or any word combination upon reentry, it came up with this :

------------------------------------------------------------------------------------------------------
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lifenzc/public_html/phppractice/viewadj.php on line 285
------------------------------------------------------------------------------------------------------

So I figure somewhere along the line I have used a "=" sign or something that only works for numbers? Here is the script I have used, haven't yet been able to figure it out.



<?php

$do=mysql_query("SELECT * FROM journals ORDER BY date DESC LIMIT 2");
while ($fetch=mysql_fetch_array($do)) {
$dispd = $fetch[jtitle];
echo '<TD align=center class=maintable><a href="'.$PHP_SELF.'?jc='.$dispd.'">'.$dispd.'</a></td>';

}

?>


Then inside the if jc has a value section upon reload of page:


<?php if ( isset($jc) ): ?>



<TR><TD align=center class=menutitle>
<?php

$showja=mysql_query("SELECT * FROM journals where jtitle=$jc");
while ($jja=mysql_fetch_array($showja)) {
$showjoud = $jja[date];
$showjout = $jja[jtitle];
$showjouj = $jja[jadvent];
$showjouu = $jja[userswj];
}
?>
</td></tr>

Any ideas? = D
Link to comment
https://forums.phpfreaks.com/topic/10766-a-few-nublet-questions/#findComment-40771
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.