bakr_2k5
Dec 3 2006, 07:25 PM
Hello you all, I've got a question  Let's say I have a database width the table "news". It contains about 10 items which is ordered by the field "id". Now from my admin page i do this: CODE <?PHP mysql_query("DELETE FROM news WHERE id=4"); ?> And a few days later i do: CODE <?PHP mysql_query("DELETE FROM news WHERE id=7"); ?> Now there are two gaps in the table => 1, 2, 3, 5, 6, 8, 9, 10 (no 4 and 7). It want to reallocate the whole table to fill the gaps like this => 1, 2, 3, 4, 5, 6, 7, 8. Of course true a php script which lies in my admin environment. But I can't figure out how to, so i thought let's ask it here  Bakr_2k5 EDIT: Perhaps it can be done with a temporary table or something like that, but still don't know really how. And it would be nicer if it could be done without the temporary table  END EDIT
Reply
miCRoSCoPiC^eaRthLinG
Dec 4 2006, 11:18 AM
Are you sure you want to do this? In case these IDs act as references (FOREIGN KEYS) to other tables - that might collapse the whole database structure and create a lot of orphaned/mis-linked records - and that's not desirable at all. Anyways, I believe I'd come across a statement which does what you want - but can't recall it at the moment. Let me jog my memory a bit and I'll get back to you.
Reply
pyost
Dec 4 2006, 11:56 AM
I don't have time to write the PHP script, so I'll just try to explain what I have in mind. First, you select all the rows in that table. Next, you start a while loop that will go through all those rows. Also, you create a new variable, let's say $i, which is 1. Now, in the loop, if the current row isn't empty, you will save it in the same table, but the row will be $i, and then you will increase $i. If, however, the row is empty, just increase $i without saving anything. What will you accomplish this way? You will go through all the rows, and save them one after another if they are not empty. Be aware, that this would leave you with a certain number of unwanted rows. You can delete this by starting from row $i (as $i will be the row after the last one). I hope I was clear enough
Reply
bakr_2k5
Dec 4 2006, 02:08 PM
QUOTE(pyost @ Dec 4 2006, 11:56 AM)  I don't have time to write the PHP script, so I'll just try to explain what I have in mind. First, you select all the rows in that table. Next, you start a while loop that will go through all those rows. Also, you create a new variable, let's say $i, which is 1. Now, in the loop, if the current row isn't empty, you will save it in the same table, but the row will be $i, and then you will increase $i. If, however, the row is empty, just increase $i without saving anything. What will you accomplish this way? You will go through all the rows, and save them one after another if they are not empty. Be aware, that this would leave you with a certain number of unwanted rows. You can delete this by starting from row $i (as $i will be the row after the last one). I hope I was clear enough  @pyost: This isn't exactly what I had in mind. You see, the "empty" rows don't exist. They are deleted true the mysql DELETE thing. Which ends up with 1,2,3,5,6,8,9,10 (4 and 7 are deleted) so those aren't empty they just don't exist. And I have set the "id" field from the "news" table to "auto increment". BUT when I delete a row 4&7, the id's don't get updated to "recount auto_increment" so it leaves a gap between id 3&5 and 6&8. Well there isn't more to say I think. Maybe you don't exactly understand what I mean, but I'm no professional in English  ! Although your explanation was very clear but just not what I'm looking for. (Hmm... It could also be that I don't understand what you mean, but then I'll hear it from you  ) Well thanks anyways! @miCRoSCoPiC^eaRthLinG: I hope you can dig it somewhere from your memory  Bakr_2k5
Reply
jlhaslip
Dec 4 2006, 04:17 PM
The gaps in the index for this table are not critical to anything. The Index does not need to be continuous at all, what-so-ever. As mentioned by m^e, you could create more grief by messing with this than it is worth to have nice, neat indexes. Let the MySql worry about that.
Reply
bakr_2k5
Dec 4 2006, 04:24 PM
QUOTE(jlhaslip @ Dec 4 2006, 04:17 PM)  The gaps in the index for this table are not critical to anything. The Index does not need to be continuous at all, what-so-ever. As mentioned by m^e, you could create more grief by messing with this than it is worth to have nice, neat indexes. Let the MySql worry about that.
Yes that's completely true, but it was just a thought that popped into my head!  And it was more like a question if it was possible. But I'd guess it IS possible but like m^e and you said it's not worth it, and could break things. So I'll quickly "remove" the thought and go on with life  Thank you all anyways!! Bakr_2k5
Reply
pyost
Dec 4 2006, 07:15 PM
QUOTE(bakr_2k5 @ Dec 4 2006, 03:08 PM)  This isn't exactly what I had in mind. You see, the "empty" rows don't exist.
Oh, this makes it even easier. Again, you select all the rows, and create a variable $i = 1. In a "while" loop you go through all the rows and check if id is equal to $i. If it is, you just increase $i and go to the next row. If it is not, you update the current row so that id becomes $i, increase $i and move on to the next row. I hope this is what you were asking for
Reply
bakr_2k5
Dec 4 2006, 08:27 PM
QUOTE(pyost @ Dec 4 2006, 09:15 PM)  Oh, this makes it even easier. Again, you select all the rows, and create a variable $i = 1. In a "while" loop you go through all the rows and check if id is equal to $i. If it is, you just increase $i and go to the next row. If it is not, you update the current row so that id becomes $i, increase $i and move on to the next row. I hope this is what you were asking for   That's EXACTLY what I meant! Thank you! Damn, I'm not clearly minded these days. It's so simple and even can't think of this! Hmm maybe I was thinking a bit too much the difficult way!  Anyway thanks, if I need it I know how to  ... Although those posts earlier from m^e and jlhaslip kinda discouraged me to do this. But I might be handy sometime! Bakr_2k5
Reply
TavoxPeru
Dec 6 2006, 02:34 AM
QUOTE(bakr_2k5 @ Dec 4 2006, 03:27 PM)   That's EXACTLY what I meant! Thank you! Damn, I'm not clearly minded these days. It's so simple and even can't think of this! Hmm maybe I was thinking a bit too much the difficult way!  Anyway thanks, if I need it I know how to  ... Although those posts earlier from m^e and jlhaslip kinda discouraged me to do this. But I might be handy sometime! Bakr_2k5 Yes it is so simple and efective and works perfect, but, it only works if your column id is not a foreign key in another table, but dont worry, if you have such case simply add another SQL statement that deletes the rows referenced: CODE <?php mysql_query("DELETE FROM news WHERE id=$n"); mysql_query("DELETE FROM table_with_fk WHERE table_with_fk.id=$n"); // $n = id to delete ?> Also don't forget to complete the code to update all the rows with the foreign key column in the second table when id is not equal to $i. You can also use ALTER TABLE to reset the AUTO_INCREMENT value: CODE <?php mysql_query("ALTER TABLE news AUTO_INCREMENT=$n"); // $n = row count plus 1 ?> Best regards,
Reply
yordan
Dec 6 2006, 02:45 PM
QUOTE mysql_query("DELETE FROM news WHERE id=$n"); I love this ! Because it's in a loop on the whole database ! So, in case of mistake, you detroyed the whole database !
Reply
Latest Entries
bakr_2k5
Dec 6 2006, 10:23 PM
QUOTE(NoMore @ Dec 6 2006, 11:41 PM)  i havnt read all the rplays so i am sorry if ill write what outer ppl wrote you can simply when taking out datas with PHP or any outer programing lang to increase number by one every time you take somting out, so you will get the real number and not the aout incresed number form the MySQL database or in for while (PHP mainly) to use the incereser
NoMore
Perhaps you should have read the replays since it's already solved  Of course I can't blame you  . Bakr_2k5
Reply
Recent Queries:--
php reorder - 1.09 hr back. (1)
-
reorder rows mysql - 11.84 hr back. (1)
-
reorder table mysql - 14.26 hr back. (1)
-
reorder mysql table - 29.54 hr back. (1)
-
php table order - 33.61 hr back. (1)
-
function to re-order in sql - 38.93 hr back. (1)
-
mysql reorder data - 41.12 hr back. (1)
-
mysql reorder items in a table - 46.77 hr back. (1)
-
reorder mysql - 22.20 hr back. (2)
-
mysql reorder auto increment - 51.55 hr back. (1)
-
reorder in mysql - 66.33 hr back. (1)
-
mssql reorder table - 67.15 hr back. (1)
-
reorder auto increment mysql - 74.43 hr back. (1)
-
phpmyadmin reorder rows - 77.24 hr back. (1)
Similar Topics
Keywords : , order, mysql, table
- Letting Users Add Mysql Data With Php
(1)
Mysql Question(inserting Number From A Textfield)
(3) Hey! I am trying to do a "Admin give EXP script". But I can't make it work. The value is not
updating, but the update query is correct.( I think:P) I think the fault is here: CODE
$expcomp=$givexpp += $givexp; The $givexp is the variable for the amount of Xp the admin wants
to give. the $givexpp is the variable for the user info (in this case, the experince he already
have). The datatype for the XP in the database is INT. So I have no idea if it can take data from a
normal textfield. If you need to see all the code, here you go: CODE session_start();....
Making Something In Mysql Happen Only Once
(10) Hey! I know I am asking alot. But much is happening theese days. Sorry if I disturb with my
questions. The thing I am trying to do is: Ex. If the user becomes level 2, he should get 5 skill
points. I can't do this: CODE if($userlevel=5){ mysql_query("UPDATE user SET skillpoints
=$points+5");} because then it would update everytime the code was loaded. I hope you understand
what I am trying to do. If not, tell me /smile.gif" style="vertical-align:middle" emoid=":)"
border="0" alt="smile.gif" /> and i'll try to explain better. Thanks //Feelay....
Making A Link = Mysql_query
(8) Hey! I will try to make this as clear as possible. how can I make the following. I have a list,
of all members on my site. If I press on a members name(link), I will come to his profile. To come
to his profile, I need to get out some vaule from the database, but to get out some value from the
database, I must tell the code, how it should know who the user is (hard to understand?). To do
that, I must add a mysql_query in the code ( I think), like "SELECT user FROM dbname WHERE
user=link".. This is just how I think it works. I know it is kinda wrong.. but I don't k....
Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...
This Is for My attack Script. (4) Hey. I am making a "Version 2.0" For my attack script, but I can't make it work. This is the
error I am gettin: Warning: mysql_result(): supplied argument is not a valid MySQL result resource
in And here is the code: CODE $dbQueryHealth = mysql_query("SELECT temphealth FROM
characters WHERE user =". $_POST .""); $currentHealth = mysql_result($dbQueryHealth, 0);
$dbQueryExp = mysql_query("SELECT exp FROM characters WHERE user = ".$_POST ."");
$currentExp = mysql_result($dbQueryExp, 0); I have checked the PHP Manual,....
Warning: Mysql_num_rows()
What is the error :S (1) Hey! I've made a register script.. Some time ago it worked. And I ain't sure if I changed
something since then.. The error I am getting is this: Warning: mysql_num_rows(): supplied argument
is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31 Here is
the code on theese lines: CODE $sqlCheckForDuplicate = "SELECT username FROM user WHERE username
= '". $username ."'"; if( mysql_num_rows( mysql_query(
$sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO ....
Anyone Know Of A Really Good Mysql Class?
Looking for something easy but full featured. (4) Generally speaking, when I write a script, it either utilizes the MySQL class of the parent system
(like Mambo or Joomla) or I use basic functions and snippets to perform the database queries I need.
I really like the Joomla database class as it allows you to simply pass a regular query string to
it and the data is returned without the need for extra work! The Invision Power Board (IPB)
database class which is what is used for this forum is kind of a pain to use since it wants the
query string in a non-MySQL standard format. Nonetheless, it does work and I could use i....
Extracting Mysql Maths Using Php
(2) Right, this is a really simple thing and it has me completely stumped. I'm working on this mini
maths function and for some reason i cannot seem to do some simple math process using mysql. This is
the code: (php btw), now assume that $date is actually a defined mysql date variable already
successfully extracted. $sql = mysql_query("SELECT TO_DAYS('CURDATE()') -
TO_DAYS('$date')"); while ($row = mysql_fetch_array($sql)){ $diff = $row ; } Can
anyone spot what im doing wrong becuase im just thrown by it.....
Too Many Connections?
mysql_connect() (4) I uploaded my PHP game yesterday, and most of my friends tried it out. After a while, I tried to
play as well but it said that mysql_connect() had too many connections already. Can anyone tell me
how to increase the amount of connections or maybe the total amount of connections allowed?....
Php/mysql And Manual Page Caching?
(4) I am hopefully about to attempt this on the news page of my new site. Every bit counts as far as
I'm concerned and not having "news" portion of my news page re-php and re-mysql everything where
there is no chance seems like a waste. I'm looking for good articles, information or tips on
the process (if I fail to find any good information as I'm looking through now). The way I see
it right now, I have most of my page split up in header, content (some static html in here before
dynamic contend and then a little more static html to close it off) and then a foo....
Sql Injection Prevention (passing Numerical Data Across Pages).
PHP/mySQL (9) Even if your building something as simple as a basic news page for your website, if your passing
along url variable strings like (mysite/index.php?page=1), you may be vulnerable to SQL injection
attacks. For cases like these (passing numerical data in url strings), I have a handy dandy little
function to thwart these attempts silly: CODE // For checking if value is a number, if not
return 1. function isNum($val) { if (!is_numeric($val)) { $val = 1; } return ($val); } I
have this function, within my functions.php file, which I use as an include in files w....
Php Mysql Errors
Fetching arrays (2) I am deciding to make a Multiplayer Online RPG type game. I will be building it off of PHP and MySQL
to ensure makimum compatibility with Astahost's services (and it makes it easier /wink.gif"
style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />). I have a database setup with
1 table to hold user data and I have the login system setup properly as well as the registration
form (obviously). All games of course have something similar to gold, units and points. Because
this is a turn-based game, I have turns. Now for the problem: I am trying to echo ....
How To Show Serial Nums In PHP Table For Contents Of MySQL DB
Serial Numbering for output contents of mysql in php table (4) Hello there, I'm looking for some education. How would you show the serial numbering for
outputted contents of mysql database. I used a table created in PHP to output content (i.e. an
alumni database) and I created a column for S/N, so that at a glance anyone can tell how many
members have registered. Thanks house. Neyoo....
PHP & MySQL: Displaying Content From A Given ID
(6) Okay so I got this sample link (not working): http://www.acosta.com/joo.asp?id=654 Now suppose
I have a PHP file that would use MySql in order to get all values in the row where id 654 is found.
Here's a sample DB: Table: demnyc ______________________________________ | id |
Name | Age | Email | *----------------------------------------------------* | 1
| Albert | 17 | no email |
*----------------------------------------------------* | 2 | YaPow | 888 |
no email | |__________....
Need MySQL Alternative To The Syntax "or die()"
(8) Hello again /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
I'm facing a problem with PHP and MySQL... I want, when a MySQL error occurs, to let the script
continue. Here's the script: CODE $query = "SELECT * FROM menus ORDER BY id ASC";
$menus_result = mysql_query($query) or die("Error!"); while( $menu=mysql_fetch_array($menus_result)
) { echo $menu ." "; } Now if the table "menus" doesn't exist, this would echo "Error!"
where it's placed and terminate the whole script. But I want it to echo "Error!" and....
Need Help With Php/mysql And Web Servers Such As Asta's.
(4) Within my site I have built my own basic forum using PHP/Mysql, I always test locally now both using
EasyPHP and WAMP5 which both give me no problems what so ever. But when I tryed to run the exact
same code on Asta's hosting services (and possible another I used to use) when creating a new
thread or adding a reply to an existing one it *sometimes* adds an additional thread/reply as a
Guest (someone not signed in) with an empty message. This would lead me to believe that somehow the
page is being refreshed and the variables sent to the database update php file are ....
Important: Basics Of Using PHP And MySQL
(10) I generally notice confusion with new users to PHP and or MySQL and first of all I believe that
unlike HTML which is automatically associated with a IE browser in a Microsoft system. HTML is
automatically rendered with whatever browser is the default browser, be it Internet Expolrer Firefox
Netscape or any other browser that has been set. PHP is a different matter to view the output of a
PHP file it must be run on a webserver, and if you do not have one set up on your local PC it simply
will not work. (Note serverside langauge requies a server) HTML is client side and ....
How Do You Create A Secure Loging?
with PHP and mySQL (4) I've read a few articles, and looked up the code of certain files and some of them seem to work
differently. I'm trying to create a login script, which would require PHP and mySQL to run,
however, I'm not quite sure how to approach it since I'm only just learning PHP. I'd
like to know, what is the most secure and effective login? I've heard you can add a salt to
encrypted passwords, etc, and well as using sessions (sid). It's just like to know what methods
are best for creating a secure login script. Thank yo ufor readin this. ....
[php] Index.php?section=xx&pag=yy
No MySQL or any other database (6) Hi everybody. This is my 3rd script, but this dont use MySQL It does this: divide the site in
SECTIONS and PAGES. Benefits: -You have to create just the text of your pages, no create ech page
with the entire layout again. -If its just the text that is included, you just have to have one page
with the layout, witch is the INDEX.PHP. -If you chanche the layout in the index.php, you DONT HAVE
TO change in the other pages. Here is the code: CODE
//-----------------------------------------// //ACAF Paginação //
//by Alexandre Cisneiros ....
[PHP + MySQL] Encrypting Data
To protect the password of your DB, for example. (11) Hi! This is my 2nd code of PHP + MySQL. This code is VERY simple: it encript the data in the MySQL
DB. Here we go! ------------------------------------------------------------------------ CODE
$password = "abc"; $new_password = md5($password); echo $new_password; ?> The password "abc"
was codfied using md5() This will be: 900150983cd24fb0d6963f7d28e17f72 CODE $normal_pass =
"abc"; $encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($normal_pass) ==
$encripted_pass) echo "Login Sucessful!"; else echo "Incorrect password."; ?> This c....
[PHP + MySQL] Separating The Results By Pages
Simple code (0) Hi! I will post here a code for separating the results of MySQL in pages. You ask: Why separete? I
answer: Imagin that you have 1523 results to display. I dont have to say anything. =P Here is it.
------------------------------------------------------------------- CODE $conect =
mysql_connect("host","user","password"); $select_db = mysql_select_db("database"); $query = "SELECT
* FROM mytable"; $results = "15"; //Number of results displayed per page. if (!$page) {
$counter = "1"; } else { $pcounter = $page; } $start = $counter - 1; $start = $counter *
$resu....
Need Some Help Using PHP & MySQL
(4) I wonder if its possible or if anyone know how to : I'm making a website for my soccer team
and every week there are new news, but in the index file i only show some part of the text and the
rest of the news is in Stored in Database, of course that all news are inside mysql database, i only
set a script to get from the Database the text and title and so. My doubt is if there is some how to
attach a link to that news and when i run the link, this show me another page but with FULL news
text ? i Read something like, i've to create a cicle CODE ....
Printing Out A Table
PHP and MySQL (6) I've been designing an online registration page for my univ. The adminstrative section is going
to take care of the registration and they've asked me if I could incorporate a PRINT link on the
page which displays the details of the students so that they can take a printout directly of just
the table and not the extra links and decorations on the page without having to copy the whole thing
into excel or something. Does anyone have any ideas of how to do this? To make myself more clear,
here's a screenshot of the admin page: I want a printout of just the....
Need For PHP/MySQL Creator
(1) need for PHP/MYSQL creator I need a PHP/MYSQL application creator that have php function and
create php codes automatically, for example:Macromedia Dreamweaver MX 2004 have this ability to
create php applications already i downloaded PHP designer but it didn`t applications ....
Need Help With A PHP - MySQL Registration Script
Wont INSERT into the database (13) hey well can some one helpme make this code work it won't INSERT INTO THE DATABSE CODE #
register1.php # common include file to MySQL include("DB.PHP"); $Username=$_POST ; $Password=$_POST
; $Name=$_POST ; $Last=$_POST ; $Sex=$_POST ; $Month=$_POST ; $Day=$_POST ; $Year=$_POST ;
$Adresse=$_POST ; $City=$_POST ; $State=$_POST ; $Zipcode=$_POST ; $Country=$_POST ; $Phone=$_POST ;
$Email=$_POST ; $Father_Name=$_POST ; $Mother_Name=$_POST ; $Parent_Phone=$_POST ;
$Parent_Email=$_POST ; $Level=$_POST ; $Academic=$_POST ; $Image_Link=$_POST ; $sql9="INSERT INTO
U....
Php/mysql Data Display
(3) Okay .. got a bit of a question here, so I'll do some explaining. I was asked to do a site for
an online roleplaying game, specifically, a "blackbook" site. I accepted and began my quest for
knowledge of PHP. I've gotten quite "far" to the point that I can now take a user inputted
search value and query the database with that value, and then display the values in a table. My
MySQL table setup is as below: CODE |Name|Reports|Type1|Type2|Quote|Confirmed| When queried
it displays the following: CODE Violator Name: # Reports: Offense(s): Quote: ....
Php/mysql Function Problem
(2) I am having a problem with some of the php/mysql functions. What I want to do is display the
results that a MySQL shell would give a user when executing a query. Using the mysql_query()
function I get a resource, but the mysql_fetch_row() and mysql_fetch_object() functions do not seem
to be working. If requested, code can be provided, but what I'm looking for is more of an
example on how to use these functions or other functions to display the output of a query. Thank
you. ~Viz....
Help With Multi Tier Mysql Application Over Net
receiving data connection from client (6) hi.. i want to make a connection from my desktop client into mysql database at web server.
currently i think it can be provided by PHP. 1. i'm thinking like this: CLIENT -> PHP + MYSQL
CLIENT {sent file} -> PHP {receive file, open connection to MYSQL, insert data from file} how it
will be done ??? 2. the security do you know how to secure it ? thanks......
Displaying Data From Mysql?
(2) how can i display data from mysql with php, just that on one page i want to display only the first
10 things and the next page the next 20 ...etc.. how can i do that? ....
MySQL & PHP coding
(9) So it seems as though the php docs make it very clear that mysql and mysqli functions will all
connect to the database as a latin1 client. Although i have my server set up with utf8 databases,
tables and fields and the default client connection is utf8, php still connects as latin1. My
xhtml forms and pages are all utf-8, so when i post utf8 data and insert it into the database the
connection assumes that incoming data is latin1 and the data that gets placed in the database is
invalid. phpMyAdmin seems to be able to view, add, edit, and retrieve utf8 strings in the d....
Looking for , order, mysql, table
|
*SIMILAR VIDEOS*
Searching Video's for , order, mysql, table
|
advertisement
|
|