Jump to content

mysql + php dropdown


wrathican

Recommended Posts

Hi guys, this is something i have created before and is usually no problem.

im selecting 2 cols from a tables where one col = userid

the user id is in a session, which i am getting the id from.

 

the problem is that even though i have a record in my table the 2 values im pulling dont appear.

although, i have many rows and its only showing the values for the second/third etc rows.

 

why cant i see the values for the first row?

 

all the userid's in the table are the same

Link to comment
https://forums.phpfreaks.com/topic/105707-mysql-php-dropdown/
Share on other sites

here is the code:

<?php


$userid = $_SESSION['userid'];
$query = "SELECT album_id, album_name FROM ls12_album WHERE album_ownerid='".$userid."'";
$result = mysql_query($query);
$array = fetchArray($result);
$numRows = mysql_num_rows($result);
if($numRows == 0){
echo "Sorry, but none of the albums belong to you. Please create an album.";
}else{
echo $userid;
?>
<form action="../functions/memberfunctions.php?func=addimage" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum">
Add To Album:<br />
<?php

echo '<select name="albumId">';
while ($row = mysql_fetch_array($result)) {
//declare vars
$albumid = $row['album_id'];
$albumtitle = $row['album_name'];

echo '<option value="'.$albumid.'">'.$albumtitle.'</option>';
}
echo "</select>";

?>
<br />
Image Title:<br />
<input name="imgName" type="text" id="txtName"><br />
Description:<br />
<textarea name="imgDesc" cols="50" rows="4" id="mtxDesc"></textarea><br />
Image:<br />
<input name="fileImage" type="file" class="box" id="fleImage"><br />
<input name="btnAdd" type="submit" id="btnAdd" value="Add Image"> 
<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();">
</form>

<?php
}

?>

Link to comment
https://forums.phpfreaks.com/topic/105707-mysql-php-dropdown/#findComment-541607
Share on other sites

fair enough here ya go:

<?php
//Included files
include "../includes/misc.inc";
include "../includes/opendb.inc";
include "../includes/functions.inc";

//start session
session_start();

//breadcrumb
$page_title = "Gallery Admin";
include('../includes/breadcrumb.inc');


//checked if logged in
if ($_SESSION['loggedin'] != "yes") {
header('Location: ../login.php');
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/ls12template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>LS12Style - That's Right... <?php echo $page_title ?></title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link rel="stylesheet" href="../ls12.css" type="text/css" />
<!-- InstanceEndEditable -->
</head>

<body>
<div id="container">
<div id="header">
<img src="../images/ls12logo4.gif" alt="LS12Style - That's Right..." width="650" height="100" /></div>
<div id="login">
<?php

if ($_SESSION['loggedin'] == "yes") {
?>
Hello! <?php echo $_SESSION['username']; ?>. <a href="../functions/functions.php?func=logout">Logout</a>
<?php
}else{

?>
<form class="form" action="../functions/functions.php?func=login" method="post" name="login">
Username:<input class="text" type="text" name="username" />
Password:<input class="text" type="password" name="password" />
<input class="submit" type="submit" name="submit" value="Go!" />
<a href="../register.php">Register</a></form>
<?php
}
?>
</div>
<div id="navi">
<ul>
<li><a href="../index.php">Home</a> | </li>
<li><a href="../about.php">About Us</a> | </li>
<li><a href="../pictures.php">Pictures</a> | </li>
<li><a href="../videos.php">Videos</a> | </li>
<li><a href="../contact.php">Contact Us</a></li>
</ul>
<?php

if ($_SESSION['loggedin'] == "yes" && $_SESSION['level'] != 0) {
?>
<ul>
<li><a href="pictures.php">Add Pictures</a> | </li>
<li><a href="videos.php">Add Video</a> | </li>
<li><a href="forum.php">Forums</a> | </li>
<li><a href="details.php">Change Details</a> | </li>
<li><a href="announce.php">Announcements</a> | </li>
<li><a href="password.php">Change Password</a></li>
<?php
if ($_SESSION['level'] == 1) {
	?>
	 | <li><a href="../admin/index.php">Admin</a></li>
	<?php
}
?>
</ul>
<?php
}
?>
</div>
<div id="conttop">
</div>
<div id="content">
<!-- InstanceBeginEditable name="title" --><h1 class="cont"><?php echo $page_title ?></h1><!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="content" -->
<?php

if((isset($_SESSION['errorstate'])) && ($_SESSION['errorstate'] == 1)) {
echo '<span id="error">';
foreach($_SESSION['errormessage'] as $key => $value){
	echo $value.'<br />';

}
$_SESSION['errorstate'] = "";
$_SESSION['errormessage'] = "";
echo '</span><br />';
}

switch ($_GET['page']) {

//create album
case "addalbum":
?>

<form action="../functions/memberfunctions.php?func=addalbum" method="post" enctype="multipart/form-data" name="frmAlbum"v class="form">
Album Name:<br />
<input name="title" type="text" id="txtName"><br />
Description:<br />
<textarea name="desc" cols="50" rows="4" id="mtxDesc"></textarea><br />
Title Image:<br />
<input name="image" type="file" class="box" id="fleImage"><br />
<input name="btnAdd" type="submit" id="btnAdd" value="Add Album"> 
<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();">
</form>

<?php
break;

//add picture to an album
case "addimage":

$userid = $_SESSION['userid'];
$query = "SELECT album_id, album_name FROM ls12_album WHERE album_ownerid='".$userid."'";
$result = mysql_query($query);
$array = fetchArray($result);
$numRows = mysql_num_rows($result);
if($numRows == 0){
echo "Sorry, but none of the albums belong to you. Please create an album.";
}else{
echo $userid;
?>
<form action="../functions/memberfunctions.php?func=addimage" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum">
Add To Album:<br />
<?php

echo '<select name="albumId">';
while ($row = mysql_fetch_array($result)) {
//declare vars
$albumid = $row['album_id'];
$albumtitle = $row['album_name'];

echo '<option value="'.$albumid.'">'.$albumtitle.'</option>';
}
echo "</select>";

?>
<br />
Image Title:<br />
<input name="imgName" type="text" id="txtName"><br />
Description:<br />
<textarea name="imgDesc" cols="50" rows="4" id="mtxDesc"></textarea><br />
Image:<br />
<input name="fileImage" type="file" class="box" id="fleImage"><br />
<input name="btnAdd" type="submit" id="btnAdd" value="Add Image"> 
<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.history.back();">
</form>

<?php
}
break;

//edit albums belonging to the user or all if admin
case "editalbum":

break;

//edit pictures titles and descritions
case "editpic":

break;

default:
?>
<ul>
<li><a href="?page=addalbum">Create Album</a></li>
<li><a href="?page=addimage">Add Images</a></li>
<li><a href="?page=editalbum">Edit Album</a></li>
<li><a href="?page=editpic">Edit Picture</a></li>
</ul>
<?php
}

//close db connection
include "../includes/close.inc";
?>
<!-- InstanceEndEditable --></div>
<div id="contbottom"></div>
<div id="footer">Copyright © 2008 Ashley Broadley</div>
</div>
</body>
<!-- InstanceEnd --></html>

Link to comment
https://forums.phpfreaks.com/topic/105707-mysql-php-dropdown/#findComment-541616
Share on other sites

try assoc

 

also mate remember any .inc anyoe can see change it mate to a .php include "../includes/close.php";

 

code looks good to me it that dam loop of array say

 

<?php

echo '<select name="albumId">';
while ($row = mysql_fetch_assoc($result)) {
//declare vars
$albumid = $row['album_id'];
$albumtitle = $row['album_name'];

echo '<option value="'.$albumid.'">'.$albumtitle.'</option>';
}
echo "</select>";

?>

Link to comment
https://forums.phpfreaks.com/topic/105707-mysql-php-dropdown/#findComment-541620
Share on other sites

thanks for your help.

 

unfortunately that did not work.

 

its very strange. I have 4 records. all made using the "addalnum" case before the "addimage" one in that script.

 

but when i come to add an image to an album i can only see 3 albums...

 

 

Oh, and good point on that include advice. i never thought about that!!!

Link to comment
https://forums.phpfreaks.com/topic/105707-mysql-php-dropdown/#findComment-541630
Share on other sites

ok so i changed the includes :)

 

but thats not the issue here.

 

i emptied my table and started again from scratch with regards to entries.

 

i added the first album to my table and its there on my mysql editor.

 

it doesnt show in the drop down

 

i added another, and boom its there in the drop dow. but only that one is there and not the first one.

Link to comment
https://forums.phpfreaks.com/topic/105707-mysql-php-dropdown/#findComment-541638
Share on other sites

wonder if +1 would work a guess never tried it ever only a fort............

<?php

echo '<select name="albumId">';
while ($row = mysql_fetch_assoc($result)+1) {
//declare vars
$albumid = $row['album_id'];
$albumtitle = $row['album_name'];

echo '<option value="'.$albumid.'">'.$albumtitle.'</option>';
}
echo "</select>";

?>

Link to comment
https://forums.phpfreaks.com/topic/105707-mysql-php-dropdown/#findComment-541672
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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