11/05/2011, 07:53
|
| | Fecha de Ingreso: mayo-2011
Mensajes: 4
Antigüedad: 13 años, 6 meses Puntos: 0 | |
Respuesta: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL r
Código:
<?php function showroweditor($row, $iseditmode)
{
global $conn;
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Clave")." " ?></td>
<td class="dr"><input type="text" name="Clave" maxlength="20" value="<?php echo str_replace('"', '"', trim($row["Clave"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Asignatura")." " ?></td>
<td class="dr"><textarea cols="35" rows="4" name="Asignatura" maxlength="100"><?php echo str_replace('"', '"', trim($row["Asignatura"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Escuela")." " ?></td>
<td class="dr"><select name="Escuela">
<?php
$lookupvalues = array("Bioanalisis","Enfermeria","Medicina");
reset($lookupvalues);
foreach($lookupvalues as $val){
$caption = $val;
if ($row["Escuela"] == $val) {$selstr = " selected"; } else {$selstr = ""; }
?><option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo $caption ?></option>
<?php } ?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")." " ?></td>
<td class="dr"><select name="Nivel">
<?php
$lookupvalues = array("1er Ano","2do Ano","3er Ano","4to Ano","5to Ano");
reset($lookupvalues);
foreach($lookupvalues as $val){
$caption = $val;
if ($row["Nivel"] == $val) {$selstr = " selected"; } else {$selstr = ""; }
?><option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo $caption ?></option>
<?php } ?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Inicio")." " ?></td>
<td class="dr"><input type="text" name="Inicio" value="<?php echo str_replace('"', '"', trim($row["Inicio"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Fin")." " ?></td>
<td class="dr"><input type="text" name="Fin" value="<?php echo str_replace('"', '"', trim($row["Fin"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Archivo")." " ?></td>
<td class="dr">
<?php if ($iseditmode)
{
?> <input type="radio" name="a_Archivo" id="a_Archivo" value="1" checked>Keep
<input type="radio" name="a_Archivo" id="a_Archivo" value="2">Remove
<input type="radio" name="a_Archivo" id="a_Archivo" value="3">Replace<br>
<?php }
?> <input type="file" name="x_Archivo" id="x_Archivo" size="30" onChange="if (this.form.a_Archivo[2]) this.form.a_Archivo[2].checked=true;" >
</td>
</tr>
</table>
<?php } ?>
<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php?a=add">Agregar Programa</a> </td>
<?php if ($page > 1) { ?>
<td><a href="programa.php?page=<?php echo $page - 1 ?>"><< Anterior</a> </td>
<?php } ?>
<?php
global $pagerange;
if ($pagecount > 1) {
if ($pagecount % $pagerange != 0) {
$rangecount = intval($pagecount / $pagerange) + 1;
}
else {
$rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
$startpage = (($i - 1) * $pagerange) + 1;
$count = min($i * $pagerange, $pagecount);
if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
for ($j = $startpage; $j < $count + 1; $j++) {
if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="programa.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="programa.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td> <a href="programa.php?page=<?php echo $page + 1 ?>">Siguiente >></a> </td>
<?php } ?>
</tr>
</table>
<?php } ?>
<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php">Inicio</a></td>
<?php if ($recid > 0) { ?>
<td><a href="programa.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Programa Anterior</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="programa.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Siguiente Programa</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>
<?php function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php">Inicio</a></td>
</tr>
</table>
<hr size="1" noshade>
<form enctype="multipart/form-data" action="programa.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
"id" => "",
"Clave" => "",
"Asignatura" => "",
"Escuela" => "",
"Nivel" => "",
"Inicio" => "",
"Fin" => "");
showroweditor($row, false);
?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php } ?>
<?php function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php?a=add">Agregar Programa</a></td>
<td><a href="programa.php?a=edit&recid=<?php echo $recid ?>">Modificar</a></td>
<td><a href="programa.php?a=del&recid=<?php echo $recid ?>">Borrar</a></td>
</tr>
</table>
<?php
mysql_free_result($res);
} ?>
<?php function editrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("edit", $recid, $count);
?>
<br>
<form enctype="multipart/form-data" action="programa.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid" value="<?php echo $row["id"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php
mysql_free_result($res);
} ?>
<?php function deleterec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
mysql_data_seek($res, $recid);
$row = mysql_fetch_assoc($res);
showrecnav("del", $recid, $count);
?>
<br>
<form action="programa.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xid" value="<?php echo $row["id"] ?>">
<?php showrow($row, $recid) ?>
<p><input type="submit" name="action" value="Confirmar"></p>
</form>
<?php
mysql_free_result($res);
} ?>
<?php function connect()
{
$conn = mysql_connect("localhost", "root", "123456");
mysql_select_db("dae");
return $conn;
}
function sqlvalue($val, $quote)
{
if ($quote)
$tmp = sqlstr($val);
else
$tmp = $val;
if ($tmp == "")
$tmp = "NULL";
elseif ($quote)
$tmp = "'".$tmp."'";
return $tmp;
}
function sqlstr($val)
{
return str_replace("'", "''", $val);
}
function sql_select()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT `id`, `Clave`, `Asignatura`, `Escuela`, `Nivel`, `Inicio`, `Fin`, `Archivo` FROM `programa`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`Clave` like '" .$filterstr ."') or (`Asignatura` like '" .$filterstr ."') or (`Escuela` like '" .$filterstr ."') or (`Nivel` like '" .$filterstr ."') or (`Inicio` like '" .$filterstr ."') or (`Fin` like '" .$filterstr ."') or (`Archivo` like '" .$filterstr ."')";
}
if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = mysql_query($sql, $conn) or die(mysql_error());
return $res;
}
function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT COUNT(*) FROM `programa`";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (`Clave` like '" .$filterstr ."') or (`Asignatura` like '" .$filterstr ."') or (`Escuela` like '" .$filterstr ."') or (`Nivel` like '" .$filterstr ."') or (`Inicio` like '" .$filterstr ."') or (`Fin` like '" .$filterstr ."') or (`Archivo` like '" .$filterstr ."')";
}
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($res);
reset($row);
return current($row);
}
continua.. |