Jump to content


Photo

A few nublet Questions!


  • Please log in to reply
11 replies to this topic

#1 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 30 May 2006 - 10:17 AM

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...


#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 02:17 PM

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

2. Let's say you have an "id" field and a "username" field:
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>'

3. You can use "SELECT * FROM table ORDER BY date ASC LIMIT 1"
~ D Kuang

#3 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 31 May 2006 - 02:55 AM

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.....

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 31 May 2006 - 02:57 AM

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.
~ D Kuang

#5 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 31 May 2006 - 11:30 AM

[!--quoteo(post=378573:date=May 30 2006, 09:57 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ May 30 2006, 09:57 PM) View Post[/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

#6 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 31 May 2006 - 11:49 AM

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:
$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>";
}
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:
  echo '<a href="page.php?p='.$fetch['id'].'">Journal Page '.$fetch['id'].'</a>";
That will make something like this: page.php?=id (where "id" is the value)

Make sense?
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#7 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 01 June 2006 - 02:47 AM

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

#8 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 01 June 2006 - 12:37 PM

Immediately before the second SELECT query enter this:
echo "jc=$jc";
exit;
I have a feeling that $jc doesn't actually contain anything when being passed to that function.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#9 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 02 June 2006 - 11:54 PM

Hi that doesn't seem to be working, JC has a value its not just not getting values for the other parts of the array :/

#10 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 03 June 2006 - 12:36 AM

I would put the two pages together.

Less headaches ;)
~ D Kuang

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 03 June 2006 - 01:05 AM

$showja=mysql_query("SELECT * FROM journals where jtitle='$jc'");
Try that query instead - note ' marks around $jc
Legend has it that reading the manual never killed anyone.
My site

#12 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 03 June 2006 - 11:41 AM

will try andy... it is already one page




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users